Skip to content

Commit

Permalink
Use remote config to show start msg.
Browse files Browse the repository at this point in the history
  • Loading branch information
feilongfl authored and Haleydu committed Aug 6, 2020
1 parent ad7d2bd commit 93a3016
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72"
implementation 'com.google.firebase:firebase-analytics:17.4.4'
implementation 'com.google.firebase:firebase-crashlytics:17.1.1'
implementation 'com.google.firebase:firebase-config:19.2.0'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PreferenceManager {
public static final String PREF_APP_VERSION = "pref_app_version";

public static final String PREF_MAIN_NOTICE = "pref_main_notice";
public static final String PREF_MAIN_NOTICE_LAST = "pref_main_notice_last";

public static final String PREF_READER_MODE = "pref_reader_mode";
public static final String PREF_READER_KEEP_BRIGHT = "pref_reader_keep_on";
Expand Down
39 changes: 36 additions & 3 deletions app/src/main/java/com/hiroshi/cimoc/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.navigation.NavigationView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;

import android.util.Log;
import android.util.SparseArray;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
import com.hiroshi.cimoc.App;
import com.hiroshi.cimoc.R;
import com.hiroshi.cimoc.component.ThemeResponsive;
Expand Down Expand Up @@ -504,10 +512,35 @@ private void changeTheme(@StyleRes int theme, @ColorRes int primary, @ColorRes i
}

private boolean showAuthorNotice() {
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(3600)
.build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config);
mFirebaseRemoteConfig.fetchAndActivate()
.addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
Log.d("FireBase_FirstOpenMsg", "Config params updated: " + updated);
} else {
Log.d("FireBase_FirstOpenMsg", "Config params updated Failed. ");
}

String showMsg = mFirebaseRemoteConfig.getString("first_open_msg");
if (!mPreference.getBoolean(PreferenceManager.PREF_MAIN_NOTICE, false)
|| showMsg.compareTo(mPreference.getString(PreferenceManager.PREF_MAIN_NOTICE_LAST, "")) != 0) {
mPreference.putString(PreferenceManager.PREF_MAIN_NOTICE_LAST, showMsg);
MessageDialogFragment fragment = MessageDialogFragment.newInstance(R.string.main_notice,
showMsg, false, DIALOG_REQUEST_NOTICE);
fragment.show(getFragmentManager(), null);
}
}
});

if (!mPreference.getBoolean(PreferenceManager.PREF_MAIN_NOTICE, false)) {
MessageDialogFragment fragment = MessageDialogFragment.newInstance(R.string.main_notice,
R.string.main_notice_content, false, DIALOG_REQUEST_NOTICE);
fragment.show(getFragmentManager(), null);
return true;
}
return false;
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/remote_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- START xml_defaults -->
<defaultsMap>
<entry>
<key>first_open_msg</key>
<value>Welcome to Cimoc!</value>
</entry>
</defaultsMap>
<!-- END xml_defaults -->

0 comments on commit 93a3016

Please sign in to comment.