2020-01-01 21:03:53 +01:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
import android.content.Context;
|
2020-01-01 21:03:53 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2020-01-07 13:27:05 +01:00
|
|
|
import org.mian.gitnex.R;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-04-11 08:06:39 +02:00
|
|
|
import org.mian.gitnex.helpers.TimeHelper;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
2021-03-30 16:31:39 +02:00
|
|
|
import org.mian.gitnex.notifications.Notifications;
|
2020-01-01 21:03:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
protected TinyDB tinyDB;
|
|
|
|
|
|
|
|
protected Context ctx = this;
|
|
|
|
protected Context appCtx;
|
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
2021-02-13 20:31:38 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
this.appCtx = getApplicationContext();
|
|
|
|
this.tinyDB = TinyDB.getInstance(appCtx);
|
2020-04-12 17:19:33 +02:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
switch(tinyDB.getInt("themeId")) {
|
2020-04-28 14:39:41 +02:00
|
|
|
|
|
|
|
case 1:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "light");
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 2:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-04-28 14:39:41 +02:00
|
|
|
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "dark");
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2020-11-29 22:51:35 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "light");
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 3:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "light");
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 4:
|
2020-08-20 18:21:55 +02:00
|
|
|
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "dark");
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2020-11-29 22:51:35 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "light");
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-29 22:51:35 +01:00
|
|
|
case 5:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-11-29 22:51:35 +01:00
|
|
|
tinyDB.putString("currentTheme", "dark");
|
|
|
|
setTheme(R.style.AppThemePitchBlack);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
default:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("currentTheme", "dark");
|
2020-04-12 17:19:33 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2020-11-02 16:17:00 +01:00
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 20:31:38 +01:00
|
|
|
AppUtil.setAppLocale(getResources(), tinyDB.getString("locale"));
|
2021-03-30 16:31:39 +02:00
|
|
|
|
|
|
|
Notifications.startWorker(appCtx);
|
2020-04-12 17:19:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-01 21:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|