GitNex-Android-App/app/src/main/java/org/mian/gitnex/activities/BaseActivity.java

128 lines
4.2 KiB
Java
Raw Normal View History

package org.mian.gitnex.activities;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.annotation.AcraNotification;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.LimiterConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
2020-01-07 13:27:05 +01:00
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.FontsOverride;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
/**
* Author M M Arif
*/
@AcraNotification(resIcon = R.drawable.gitnex_transparent,
resTitle = R.string.crashTitle,
resChannelName = R.string.setCrashReports,
resText = R.string.crashMessage)
public abstract class BaseActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
final TinyDB tinyDb = new TinyDB(getApplicationContext());
Increasing usability and design of files diff. (#413) Applying sizes. Additional changes. First changes. Merge branch 'master' into diff-cleaner Fixing formatting. Merge branch 'master' into diff-cleaner Final changes for working with custom themes. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner First changes for working with custom themes. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Adding custom COLOR_FONT. Even smaller cleanups. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Small cleanups. Fixing bug and adding maximum line limit. Adding option to set cursor to end and small cleanup. First aid. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Few improvements. Performance improvements and cleanups. Minor improvements (code in order) and many bug fixes Bug fix. Combining cited code. Adding code commenting option. Renaming list_files_diffs_new to list_files_diffs Moving ProcessBar into center Increasing performance. Applying size to all icons globally. Removing another unused file. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Removing unused files. Changing size of 'close'-button. Major changes concerning design and bug fixes. Temporary save point. 2 1 Co-authored-by: opyale <example@example.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/413 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: M M Arif <mmarif@swatian.com>
2020-04-28 14:39:41 +02:00
switch(tinyDb.getInt("themeId")) {
case 1:
setTheme(R.style.AppThemeLight);
break;
Increasing usability and design of files diff. (#413) Applying sizes. Additional changes. First changes. Merge branch 'master' into diff-cleaner Fixing formatting. Merge branch 'master' into diff-cleaner Final changes for working with custom themes. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner First changes for working with custom themes. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Adding custom COLOR_FONT. Even smaller cleanups. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Small cleanups. Fixing bug and adding maximum line limit. Adding option to set cursor to end and small cleanup. First aid. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Few improvements. Performance improvements and cleanups. Minor improvements (code in order) and many bug fixes Bug fix. Combining cited code. Adding code commenting option. Renaming list_files_diffs_new to list_files_diffs Moving ProcessBar into center Increasing performance. Applying size to all icons globally. Removing another unused file. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Removing unused files. Changing size of 'close'-button. Major changes concerning design and bug fixes. Temporary save point. 2 1 Co-authored-by: opyale <example@example.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/413 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: M M Arif <mmarif@swatian.com>
2020-04-28 14:39:41 +02:00
case 2:
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
setTheme(R.style.AppTheme);
}
else {
setTheme(R.style.AppThemeLight);
}
break;
Increasing usability and design of files diff. (#413) Applying sizes. Additional changes. First changes. Merge branch 'master' into diff-cleaner Fixing formatting. Merge branch 'master' into diff-cleaner Final changes for working with custom themes. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner First changes for working with custom themes. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Adding custom COLOR_FONT. Even smaller cleanups. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Small cleanups. Fixing bug and adding maximum line limit. Adding option to set cursor to end and small cleanup. First aid. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Few improvements. Performance improvements and cleanups. Minor improvements (code in order) and many bug fixes Bug fix. Combining cited code. Adding code commenting option. Renaming list_files_diffs_new to list_files_diffs Moving ProcessBar into center Increasing performance. Applying size to all icons globally. Removing another unused file. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Removing unused files. Changing size of 'close'-button. Major changes concerning design and bug fixes. Temporary save point. 2 1 Co-authored-by: opyale <example@example.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/413 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: M M Arif <mmarif@swatian.com>
2020-04-28 14:39:41 +02:00
default:
setTheme(R.style.AppTheme);
Increasing usability and design of files diff. (#413) Applying sizes. Additional changes. First changes. Merge branch 'master' into diff-cleaner Fixing formatting. Merge branch 'master' into diff-cleaner Final changes for working with custom themes. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner First changes for working with custom themes. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Adding custom COLOR_FONT. Even smaller cleanups. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Small cleanups. Fixing bug and adding maximum line limit. Adding option to set cursor to end and small cleanup. First aid. Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Merge branch 'master' into diff-cleaner Few improvements. Performance improvements and cleanups. Minor improvements (code in order) and many bug fixes Bug fix. Combining cited code. Adding code commenting option. Renaming list_files_diffs_new to list_files_diffs Moving ProcessBar into center Increasing performance. Applying size to all icons globally. Removing another unused file. Merge remote-tracking branch 'remotes/main/master' into diff-cleaner Removing unused files. Changing size of 'close'-button. Major changes concerning design and bug fixes. Temporary save point. 2 1 Co-authored-by: opyale <example@example.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/413 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: M M Arif <mmarif@swatian.com>
2020-04-28 14:39:41 +02:00
break;
}
String appLocale = tinyDb.getString("locale");
AppUtil.setAppLocale(getResources(), appLocale);
super.onCreate(savedInstanceState);
setContentView(getLayoutResourceId());
switch(tinyDb.getInt("customFontId", -1)) {
case 0:
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/roboto.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/roboto.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/roboto.ttf");
break;
case 2:
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/sourcecodeproregular.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/sourcecodeproregular.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/sourcecodeproregular.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/sourcecodeproregular.ttf");
break;
default:
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/manroperegular.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/manroperegular.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "fonts/manroperegular.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/manroperegular.ttf");
break;
}
// enabling counter badges by default
if(tinyDb.getString("enableCounterBadgesInit").isEmpty()) {
tinyDb.putBoolean("enableCounterBadges", true);
tinyDb.putString("enableCounterBadgesInit", "yes");
}
// enable crash reports by default
if(tinyDb.getString("crashReportingEnabledInit").isEmpty()) {
tinyDb.putBoolean("crashReportingEnabled", true);
tinyDb.putString("crashReportingEnabledInit", "yes");
}
// default cache setter
if(tinyDb.getString("cacheSizeStr").isEmpty()) {
tinyDb.putString("cacheSizeStr", getResources().getString(R.string.cacheSizeDataSelectionSelectedText));
}
if(tinyDb.getString("cacheSizeImagesStr").isEmpty()) {
tinyDb.putString("cacheSizeImagesStr", getResources().getString(R.string.cacheSizeImagesSelectionSelectedText));
}
if(!tinyDb.getString("instanceUrlWithProtocol").endsWith("/")) {
tinyDb.putString("instanceUrlWithProtocol", tinyDb.getString("instanceUrlWithProtocol") + "/");
}
if (tinyDb.getBoolean("crashReportingEnabled")) {
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(true).setMailTo(getResources().getString(R.string.appEmail)).setSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil.getAppBuildNo(getApplicationContext()))).setEnabled(true);
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
ACRA.init(getApplication(), ACRABuilder);
}
}
protected abstract int getLayoutResourceId();
}