Merge pull request #808 from neslihanturan/oneTimePopUp

One time pop up
This commit is contained in:
Josephine Lim 2017-07-27 16:49:22 +10:00 committed by GitHub
commit a5a624f939
6 changed files with 99 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.preference.PreferenceManager;
import android.support.v4.util.LruCache;
import android.util.Log;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.stetho.Stetho;
@ -139,6 +140,10 @@ public class CommonsApplication extends Application {
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
Fresco.initialize(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
CommonsApplication.getInstance());
// Increase counter by one, starts from 1
prefs.edit().putInt("app_start_counter", prefs.getInt("app_start_counter" ,0) + 1).commit();
//For caching area -> categories
cacheData = new CacheController();

View file

@ -3,11 +3,13 @@ package fr.free.nrw.commons.contributions;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
@ -17,6 +19,7 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -27,7 +30,10 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication;
@ -110,6 +116,12 @@ public class ContributionsActivity
super.onPause();
}
@Override
protected void onStart() {
super.onStart();
displayFeedbackPopup();
}
@Override
protected void onAuthCookieAcquired(String authCookie) {
// Do a sync everytime we get here!
@ -342,4 +354,56 @@ public class ContributionsActivity
Intent contributionsIntent = new Intent(context, ContributionsActivity.class);
context.startActivity(contributionsIntent);
}
private void displayFeedbackPopup() {
Date popupMessageEndDate = null;
try {
String validUntil = "23/08/2017";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
popupMessageEndDate = sdf.parse(validUntil);
} catch (ParseException e) {
e.printStackTrace();
}
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
CommonsApplication.getInstance());
// boolean to save users request about displaying popup
boolean displayFeedbackPopup = prefs.getBoolean("display_feedbak_popup", true);
// boolean to recognize is application re-started. Will be used for "remind me later" option
int appStartCounter = prefs.getInt("app_start_counter" ,0);
// if time is valid and shared pref says display
if (new Date().before(popupMessageEndDate) && displayFeedbackPopup && (appStartCounter == 4)) {
new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.feedback_popup_title))
.setMessage(getResources().getString(R.string.feedback_popup_description))
.setPositiveButton(getResources().getString(R.string.feedback_popup_accept),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Go to the page
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse(getResources()
.getString(R.string.feedback_page_url)));
startActivity(browserIntent);
// No need to dislay this window to the user again.
prefs.edit().putBoolean("display_feedbak_popup" , false).commit();
dialog.dismiss();
}
})
.setNegativeButton(getResources().getString(R.string.feedback_popup_decline),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Dismiss the dialog and not to show it later
prefs.edit().putBoolean("display_feedbak_popup", false).commit();
dialog.dismiss();
}
})
.create().show();
}
}
}

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.theme;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
@ -109,6 +110,14 @@ public class NavigationBaseActivity extends BaseActivity
Toast.makeText(this, R.string.no_email_client, Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_developer_plans:
drawerLayout.closeDrawer(navigationView);
// Go to the page
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse(getResources()
.getString(R.string.feedback_page_url)));
startActivity(browserIntent);
return true;
case R.id.action_logout:
new AlertDialog.Builder(this)
.setMessage(R.string.logout_verification)

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/>
</vector>

View file

@ -30,6 +30,11 @@
android:icon="@drawable/ic_feedback_black_24dp"
android:title="@string/navigation_item_feedback"/>
<item
android:id="@+id/action_developer_plans"
android:icon="@drawable/ic_help_outline_black_24dp"
android:title="@string/navigation_item_developer_plans"/>
<item
android:id="@+id/action_logout"
android:icon="@drawable/ic_exit_to_app_black_24dp"

View file

@ -198,11 +198,17 @@ Tap this message (or hit back) to skip this step.</string>
<string name="navigation_item_feedback">Feedback</string>
<string name="navigation_item_logout">Logout</string>
<string name="navigation_item_info">Tutorial</string>
<string name="navigation_item_developer_plans">Developer plans</string>
<string name="nearby_needs_permissions">Nearby places cannot be displayed without location permissions</string>
<string name="no_description_found">no description found</string>
<string name="nearby_info_menu_commons_article">Commons file page</string>
<string name="nearby_info_menu_wikidata_article">Wikidata item</string>
<string name="error_while_cache">Error while caching pictures</string>
<string name="error_while_cache">Error while caching pictures</string>
<string name="feedback_popup_title">Feedback wanted</string>
<string name="feedback_popup_description">We are planning several new features and improvements for the app! Would you like to review them and provide feedback? \n\n(You can always access this by selecting "Developer plans" in the navigation drawer)</string>
<string name="feedback_popup_decline">No thanks</string>
<string name="feedback_popup_accept">Sure, take me there!</string>
<string name="feedback_page_url">https://meta.wikimedia.org/wiki/Grants:Project/Improve_\'Upload_to_Commons\'_Android_App/Renewal/User_feedback</string>
</resources>