Skip to content

Commit

Permalink
NClientV2 2.9.8
Browse files Browse the repository at this point in the history
* Crash report is now off by default
+ Added status count
  • Loading branch information
Dar9586 committed Feb 9, 2023
1 parent b971625 commit f8a741c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/com/dar/nclientv2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class MainActivity extends BaseActivity

private static final int CHANGE_LANGUAGE_DELAY = 1000;
private static boolean firstTime = true;//true only when app starting
private int failCount = 0;
private final InspectorV3.InspectorResponse startGallery = new MainInspectorResponse() {
@Override
public void onSuccess(List<GenericGallery> galleries) {
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/dar/nclientv2/StatusViewerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ public void onPageSelected(int position) {
});

TabLayout tabs = findViewById(R.id.tabs);
new TabLayoutMediator(tabs, viewPager, (tab, position) -> tab.setText(sectionsPagerAdapter.getPageTitle(position))).attach();
new TabLayoutMediator(tabs, viewPager, true, (tab, position) -> tab.setText(sectionsPagerAdapter.getPageTitle(position))).attach();
}

@Override
protected void onResume() {
super.onResume();
TabLayout tabs = findViewById(R.id.tabs);
for (int i = 0; i < tabs.getTabCount(); i++) {
tabs.getTabAt(i).setText(sectionsPagerAdapter.getPageTitle(i));
}
PlaceholderFragment fragment = getActualFragment();
if (fragment != null) fragment.reload(query, sortByTitle);
}

@Override
Expand Down
27 changes: 9 additions & 18 deletions app/src/main/java/com/dar/nclientv2/async/database/Queries.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -978,26 +977,18 @@ public static Cursor getGalleryOfStatus(String name, String filter, boolean sort
return db.rawQuery(query, new String[]{name, likeFilter, likeFilter, likeFilter});
}

public static HashMap<String, Integer> getCountsPerStatus() {
String query = String.format("select %s, count(%s) as count from %s group by %s;",
StatusMangaTable.NAME, StatusMangaTable.GALLERY, StatusMangaTable.TABLE_NAME, StatusMangaTable.NAME);
public static int getCountPerStatus(String name) {
String query = String.format("SELECT COUNT(*) FROM %s WHERE %s = ?",
StatusMangaTable.TABLE_NAME,
StatusMangaTable.NAME);
LogUtility.d(query);

Cursor cursor = db.rawQuery(query, null);
HashMap<String, Integer> counts = new HashMap<String, Integer>();

while (cursor.moveToNext()) {
try {
String status = cursor.getString(0);
int count = cursor.getInt(1);
counts.put(status, count);
} catch (Exception e) {
LogUtility.e(e);
}
int value = -1;
Cursor cursor = db.rawQuery(query, new String[]{name});
if (cursor.moveToFirst()) {
value = cursor.getInt(0);
}

cursor.close();
return counts;
return value;
}

public static void removeStatus(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ private void removeOldUpdates() {
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
ACRA.init(this);
ACRA.getErrorReporter().setEnabled(getSharedPreferences("Settings", 0).getBoolean(getString(R.string.key_send_report), true));
ACRA.getErrorReporter().setEnabled(getSharedPreferences("Settings", 0).getBoolean(getString(R.string.key_send_report), false));
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/settings/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static int getColPortStatus() {
}

public static void updateACRAReportStatus(Context context) {
ACRA.getErrorReporter().setEnabled(context.getSharedPreferences("Settings", 0).getBoolean(context.getString(R.string.key_send_report), true));
ACRA.getErrorReporter().setEnabled(context.getSharedPreferences("Settings", 0).getBoolean(context.getString(R.string.key_send_report), false));
}

public static boolean isDestroyed(Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,26 @@
import com.dar.nclientv2.async.database.Queries;
import com.dar.nclientv2.components.status.StatusManager;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;

/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentStateAdapter {
List<String> statuses;
HashMap<String, Integer> counts;

public SectionsPagerAdapter(StatusViewerActivity context) {
super(context.getSupportFragmentManager(), context.getLifecycle());
statuses = StatusManager.getNames();
counts = Queries.StatusMangaTable.getCountsPerStatus();
}

@Nullable
public CharSequence getPageTitle(int position) {
String status = statuses.get(position);
int count = 0;

if (counts.containsKey(status)) {
count = counts.get(status);
}

return String.format("%s - %d", status, count);
int count = Queries.StatusMangaTable.getCountPerStatus(status);
return String.format(Locale.US, "%s - %d", status, count);
}

@NonNull
Expand Down

0 comments on commit f8a741c

Please sign in to comment.