Skip to content

Commit

Permalink
Newest updated version of application 07_05_2021 ...
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed May 18, 2021
1 parent 4fe1ebd commit 1302a19
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class DataBaseHelper extends SQLiteOpenHelper {

protected final ArrayList<String> rows = new ArrayList<>();
protected final Context context;
protected final Context context;

public static String deleteQuery
= "delete from sites_table where name = '%s';";
Expand Down Expand Up @@ -38,11 +38,14 @@ public void addSite(Site site) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(createQuery);
for (String row : rows) { db.execSQL(row); }
for (String row : rows) {
db.execSQL(row);
}
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

public ArrayList<Site> getSites() {
Cursor cursor = getReadableDatabase().rawQuery(selectQuery, null);
Expand All @@ -54,14 +57,6 @@ public ArrayList<Site> getSites() {
String url = cursor.getString(urlId);
Site site = new Site(name, url, context);
sites.add(site);
/* boolean notAgain = true;
for (Site s : Site.getSites()) {
if (site.getName().equals(s.getName())) {
notAgain = false;
break;
}
}
if (notAgain) { sites.add(site); } */
}
cursor.close();
return sites;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
deleteFile("news.xml");
setDefaultSettings();
return true;
} else { return super.onOptionsItemSelected(item); }
} else {
return super.onOptionsItemSelected(item);
}
}

@Override
Expand All @@ -71,30 +73,40 @@ public boolean onContextItemSelected(MenuItem item) {
(dialog, which) -> closeOptionsMenu())
.setPositiveButton(R.string.str_delete_site,
(dialog, which) -> {
NewsRssItem removedItem = NewsRssItem.getLikedNews().get(info.position);
NewsRssItem removedItem = NewsRssItem.getLikedNews().get(info.position);
StringBuilder gotXml = new StringBuilder();
try (InputStream inputStream = openFileInput("news.xml")) {
Scanner scanner = new Scanner(inputStream);
while (scanner.hasNext()) { gotXml.append(scanner.nextLine()); }
} catch (IOException ignored) {}
while (scanner.hasNext()) {
gotXml.append(scanner.nextLine());
}
} catch (IOException ignored) {
}
deleteFile("news.xml");
Document doc = Jsoup.parse(gotXml.toString(), "", Parser.xmlParser());
Elements items = doc.select("item");
StringBuilder resXml = new StringBuilder();
String root = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String startTag = "<items>";
String endTag = "</items>";
try {for (Element docItem : items) {
if (docItem.select("title").text().equals(removedItem.getTitle())) { continue; }
resXml.append(docItem.toString()); }
} catch (Exception ignored) {}
try {
for (Element docItem : items) {
if (docItem.select("title").text().equals(removedItem.getTitle())) {
continue;
}
resXml.append(docItem.toString());
}
} catch (Exception ignored) {
}
String res = root + startTag + resXml.toString() + endTag;
try { openFileOutput("news.xml", MODE_APPEND).write(res.getBytes()); }
catch (IOException ignored) {}
try {
openFileOutput("news.xml", MODE_APPEND).write(res.getBytes());
} catch (IOException ignored) {
}
NewsRssItem.getLikedNews().remove(info.position);
listView.setAdapter(new NewsRssItemAdapter(this,
R.layout.list_item_layout, NewsRssItem.getLikedNews(), false));
})
})
.create();
alertDialog.show();
}
Expand All @@ -105,16 +117,19 @@ public void setDefaultSettings() {
SharedPreferences settings = getSharedPreferences(PreferenceManager.SETTINGS_NAME, MODE_MULTI_PROCESS);
AdapterView.OnItemClickListener itemListener =
(parent, view, position, id) -> startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(NewsRssItem.getLikedNews().get(position).getLink())));
Uri.parse(NewsRssItem.getLikedNews().get(position).getLink())));
listView.setOnItemClickListener(itemListener);
Comparator<NewsRssItem> defaultComparator;
switch (settings.getString(PreferenceManager.SORT_KEY, PreferenceManager.SORT_BY_DATE)) {
case PreferenceManager.SORT_BY_DATE:
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_DATE); break;
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_DATE);
break;
case PreferenceManager.SORT_BY_SITE:
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_SITE); break;
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_SITE);
break;
case PreferenceManager.SORT_BY_SIZE:
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_SIZE); break;
defaultComparator = NewsRssItem.getComparator(NewsRssItem.ItemComparators.SORT_BY_SIZE);
break;
default:
defaultComparator = (n_1, n_2) -> 0;
}
Expand All @@ -128,7 +143,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liked_news_activity);
ActionBar bar = getSupportActionBar();
if (bar != null) { bar.setDisplayHomeAsUpEnabled(true); }
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
}
listView = findViewById(R.id.liked_news_list);
setDefaultSettings();
registerForContextMenu(listView);
Expand Down
Loading

0 comments on commit 1302a19

Please sign in to comment.