Commit 76c88c8b authored by Sajal's avatar Sajal

Add easter egg to switch to dark theme

parent f55e0af0
......@@ -8,11 +8,13 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import app.insti.activity.MainActivity;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.Body;
import app.insti.api.model.Event;
......@@ -25,6 +27,7 @@ public final class Utils {
public static UpdatableList<Event> eventCache = new UpdatableList<>();
private static String sessionId;
private static RetrofitInterface retrofitInterface;
public static boolean darkTheme = false;
public static final void loadImageWithPlaceholder(final ImageView imageView, final String url) {
Picasso.get()
......@@ -114,4 +117,17 @@ public final class Utils {
context.startActivity(browse);
}
}
public static void changeTheme(FragmentActivity context) {
if (darkTheme) {
context.setTheme(R.style.AppTheme);
} else {
Toast.makeText(context, "You have unlocked super max pro mode", Toast.LENGTH_SHORT).show();
context.setTheme(R.style.AppThemeDark);
}
darkTheme = !darkTheme;
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
context.finish();
}
}
package app.insti.activity;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.NotificationChannel;
......@@ -24,8 +25,10 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
......@@ -95,7 +98,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private RetrofitInterface retrofitInterface;
private List<Notification> notifications = null;
/** which menu item should be checked on activity start */
/**
* which menu item should be checked on activity start
*/
private int initMenuChecked = R.id.nav_feed;
public static void hideKeyboard(Activity activity) {
......@@ -109,8 +114,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Utils.darkTheme) {
setTheme(R.style.AppThemeDark_NoActionBar);
}
super.onCreate(savedInstanceState);
ServiceGenerator serviceGenerator = new ServiceGenerator(getApplicationContext());
......@@ -150,10 +159,29 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
toolbar.setOnTouchListener(new View.OnTouchListener() {
private GestureDetector gestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
Toast.makeText(MainActivity.this, "You have unlocked super max pro mode", Toast.LENGTH_SHORT).show();
Utils.changeTheme(MainActivity.this);
return super.onDoubleTap(e);
}
});
@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
return true;
}
});
checkLatestVersion();
}
/** Get the notifications from memory cache or network */
/**
* Get the notifications from memory cache or network
*/
private void fetchNotifications() {
// Try memory cache
if (notifications != null) {
......@@ -174,7 +202,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
});
}
/** Show the right notification icon */
/**
* Show the right notification icon
*/
private void showNotifications() {
if (notifications != null && !notifications.isEmpty()) {
menu.findItem(R.id.action_notifications).setIcon(R.drawable.baseline_notifications_active_white_24);
......@@ -183,7 +213,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
/** Get version code we are currently on */
/**
* Get version code we are currently on
*/
private int getCurrentVersion() {
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
......@@ -193,10 +225,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
/** Check for updates in andro.json */
/**
* Check for updates in andro.json
*/
private void checkLatestVersion() {
final int versionCode = getCurrentVersion();
if (versionCode == 0) { return; }
if (versionCode == 0) {
return;
}
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getLatestVersion().enqueue(new EmptyCallback<JsonObject>() {
@Override
......@@ -258,7 +294,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
mNotificationManager.createNotificationChannel(mChannel);
}
/** Handle opening event/body/blog from FCM notification */
/**
* Handle opening event/body/blog from FCM notification
*/
private void handleFCMIntent(Bundle bundle) {
/* Mark the notification read */
final String notificationId = bundle.getString(FCM_BUNDLE_NOTIFICATION_ID);
......@@ -274,7 +312,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
);
}
/** Handle intents for links */
/**
* Handle intents for links
*/
private void handleIntent(Intent appLinkIntent) {
String appLinkAction = appLinkIntent.getAction();
String appLinkData = appLinkIntent.getDataString();
......@@ -283,9 +323,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
/** Open the proper fragment from given type and id */
/**
* Open the proper fragment from given type and id
*/
private void chooseIntent(String type, String id) {
if (type == null || id == null) { return; }
if (type == null || id == null) {
return;
}
switch (type) {
case DATA_TYPE_BODY:
openBodyFragment(id);
......@@ -304,7 +348,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Log.e("NOTIFICATIONS", "Server sent invalid notification?");
}
/** Open the proper fragment from given type, id and extra */
/**
* Open the proper fragment from given type, id and extra
*/
private void chooseIntent(String type, String id, String extra) {
if (extra == null) {
chooseIntent(type, id);
......@@ -324,18 +370,24 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
/** Open user fragment from given id */
/**
* Open user fragment from given id
*/
private void openUserFragment(String id) {
UserFragment userFragment = UserFragment.newInstance(id);
updateFragment(userFragment);
}
/** Open the body fragment from given id */
/**
* Open the body fragment from given id
*/
private void openBodyFragment(String id) {
Utils.openBodyFragment(new Body(id), this);
}
/** Open the event fragment from the provided id */
/**
* Open the event fragment from the provided id
*/
private void openEventFragment(String id) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
final FragmentActivity self = this;
......@@ -546,7 +598,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return true;
}
/** Open placement blog fragment */
/**
* Open placement blog fragment
*/
private void openPlacementBlog() {
if (session.isLoggedIn()) {
PlacementBlogFragment placementBlogFragment = new PlacementBlogFragment();
......@@ -565,7 +619,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
/** Change the active fragment to the supplied one */
/**
* Change the active fragment to the supplied one
*/
public void updateFragment(Fragment fragment) {
Log.d(TAG, "updateFragment: " + fragment.toString());
Bundle bundle = fragment.getArguments();
......@@ -577,7 +633,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
bundle.putString(Constants.USER_HOSTEL, session.isLoggedIn() && currentUser.getHostel() != null ? currentUser.getHostel() : "1");
if (fragment instanceof SettingsFragment && session.isLoggedIn())
bundle.putString(Constants.USER_ID, currentUser.getUserID());
if (fragment instanceof ComplaintsFragment && session.isLoggedIn()){
if (fragment instanceof ComplaintsFragment && session.isLoggedIn()) {
bundle.putString(Constants.USER_ID, currentUser.getUserID());
bundle.putString(Constants.CURRENT_USER_PROFILE_PICTURE, currentUser.getUserProfilePictureUrl());
}
......
......@@ -8,8 +8,7 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="themeColor">#FFFFFF</item>
<item name="themeColorInverse">#000000</item>
<item name="newsColor">#F2F2F2</item>
<item name="urlColor">@color/colorPrimary</item>
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
</style>
<style name="AppTheme.NoActionBar">
......@@ -23,8 +22,7 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="themeColor">#000000</item>
<item name="themeColorInverse">#FFFFFF</item>
<item name="newsColor">#00000000</item>
<item name="urlColor">@color/colorAccent</item>
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
</style>
<style name="AppThemeDark.NoActionBar">
......@@ -33,7 +31,7 @@
</style>
<style name="BlueAccent">
<item name="colorAccent">?attr/urlColor</item>
<item name="colorAccent">@color/colorPrimary</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
......@@ -72,4 +70,9 @@
<item name="android:textColor">#999</item>
<item name="android:textSize">12sp</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment