Merge branch 'develop' into l10n_crowdin_localization

This commit is contained in:
Thomas 2017-12-10 09:24:24 +01:00 committed by GitHub
commit 075ba124eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 251 additions and 314 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
targetSdkVersion 27
versionCode 84
versionName "1.6.4.1"
versionCode 86
versionName "1.6.5.1"
}
flavorDimensions "default"
buildTypes {
@ -21,7 +21,7 @@ android {
productFlavors {
fdroid {
}
safetynet {
playstore {
}
}
}
@ -44,6 +44,5 @@ dependencies {
implementation 'org.jsoup:jsoup:1.10.3'
implementation 'com.github.stom79:country-picker-android:1.2.0'
implementation 'com.github.stom79:mytransl:1.2'
safetynetImplementation 'com.google.android.gms:play-services-safetynet:11.6.2'
safetynetImplementation 'io.github.kobakei:ratethisapp:1.2.0'
playstoreImplementation 'io.github.kobakei:ratethisapp:1.2.0'
}

Binary file not shown.

View File

@ -16,10 +16,6 @@ package fr.gouv.etalab.mastodon.activities;
public class MainActivity extends BaseMainActivity {
@Override
protected void installProviders() {
// do nothing
}
@Override
protected void rateThisApp() {

View File

@ -151,7 +151,6 @@ public abstract class BaseMainActivity extends AppCompatActivity
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
installProviders();
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
@ -576,7 +575,9 @@ public abstract class BaseMainActivity extends AppCompatActivity
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
//Get the previous bookmark value
bookmark = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
//If null try to use the LAST_HOMETIMELINE_MAX_ID
String lastHomeTimeline = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
bookmark = sharedpreferences.getString(Helper.BOOKMARK_ID + userId, lastHomeTimeline);
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
if( account == null){
Helper.logout(getApplicationContext());
@ -851,7 +852,6 @@ public abstract class BaseMainActivity extends AppCompatActivity
new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
protected abstract void installProviders();
protected abstract void rateThisApp();

View File

@ -35,7 +35,6 @@ import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Instance;
import fr.gouv.etalab.mastodon.client.Entities.InstanceSocial;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;

View File

@ -39,7 +39,6 @@ import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

View File

@ -56,7 +56,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
* Login activity class which handles the connection
*/
public abstract class BaseLoginActivity extends AppCompatActivity {
public class LoginActivity extends AppCompatActivity {
private String client_id;
private String client_secret;
@ -71,7 +71,6 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
installProviders();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
@ -133,9 +132,9 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
}
login_instance.setAdapter(null);
ArrayAdapter<String> adapter =
new ArrayAdapter<>(BaseLoginActivity.this, android.R.layout.simple_list_item_1, instances);
new ArrayAdapter<>(LoginActivity.this, android.R.layout.simple_list_item_1, instances);
login_instance.setAdapter(adapter);
if( login_instance.hasFocus() && !BaseLoginActivity.this.isFinishing())
if( login_instance.hasFocus() && !LoginActivity.this.isFinishing())
login_instance.showDropDown();
} catch (JSONException ignored) {isLoadingInstance = false;}
@ -178,7 +177,6 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
});
}
protected abstract void installProviders();
@Override
protected void onResume(){
@ -196,7 +194,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
try {
instance = URLEncoder.encode(login_instance.getText().toString().trim(), "utf-8");
} catch (UnsupportedEncodingException e) {
Toast.makeText(BaseLoginActivity.this,R.string.client_error, Toast.LENGTH_LONG).show();
Toast.makeText(LoginActivity.this,R.string.client_error, Toast.LENGTH_LONG).show();
}
final String action = "/api/v1/apps";
final HashMap<String, String> parameters = new HashMap<>();
@ -227,7 +225,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
connectionButton.setEnabled(true);
login_two_step.setVisibility(View.VISIBLE);
if( client_id_for_webview){
Intent i = new Intent(BaseLoginActivity.this, WebviewConnectActivity.class);
Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class);
i.putExtra("instance", instance);
startActivity(i);
}
@ -278,7 +276,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(BaseLoginActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException ignored) {}
}
});

View File

@ -62,6 +62,7 @@ import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
@ -619,17 +620,22 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
Glide.with(getApplicationContext())
.asBitmap()
.load(account.getAvatar())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), Helper.addBorder(resource, account_pp.getContext()));
circularBitmapDrawable.setCircular(true);
account_pp.setImageDrawable(circularBitmapDrawable);
}
});
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
if( !disableGif)
Glide.with(getApplicationContext()).load(account.getAvatar()).apply(RequestOptions.circleCropTransform()).into(account_pp);
else
Glide.with(getApplicationContext())
.asBitmap()
.load(account.getAvatar())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), Helper.addBorder(resource, account_pp.getContext()));
circularBitmapDrawable.setCircular(true);
account_pp.setImageDrawable(circularBitmapDrawable);
}
});
}

View File

@ -32,8 +32,6 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
@ -149,10 +147,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
holder.account_fgc.setText(withSuffix(account.getFollowing_count()));
holder.account_frc.setText(withSuffix(account.getFollowers_count()));
//Profile picture
Glide.with(holder.account_pp.getContext())
.load(account.getAvatar())
.into(holder.account_pp);
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
if( account.isMakingAction()){
holder.account_follow.setEnabled(false);
}else {

View File

@ -375,9 +375,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
imParams.height = (int) Helper.convertDpToPixel(30, context);
imParams.width = (int) Helper.convertDpToPixel(30, context);
holder.status_replies_profile_pictures.addView(imageView, imParams);
Glide.with(imageView.getContext())
.load(replies.getAccount().getAvatar())
.into(imageView);
Helper.loadGiF(context, replies.getAccount().getAvatar(), imageView);
i++;
addedPictures.add(replies.getAccount().getAcct());
}
@ -602,19 +600,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
Helper.absoluteDateTimeReveal(context, holder.status_toot_date, status.getCreated_at());
if( status.getReblog() != null) {
Glide.with(holder.status_account_profile_boost.getContext())
.load(ppurl)
.into(holder.status_account_profile_boost);
Glide.with(holder.status_account_profile_boost_by.getContext())
.load(status.getAccount().getAvatar())
.into(holder.status_account_profile_boost_by);
Helper.loadGiF(context, ppurl, holder.status_account_profile_boost);
Helper.loadGiF(context, status.getAccount().getAvatar(), holder.status_account_profile_boost_by);
holder.status_account_profile_boost.setVisibility(View.VISIBLE);
holder.status_account_profile_boost_by.setVisibility(View.VISIBLE);
holder.status_account_profile.setVisibility(View.GONE);
}else{
Glide.with(holder.status_account_profile.getContext())
.load(ppurl)
.into(holder.status_account_profile);
Helper.loadGiF(context, ppurl, holder.status_account_profile);
holder.status_account_profile_boost.setVisibility(View.GONE);
holder.status_account_profile_boost_by.setVisibility(View.GONE);
holder.status_account_profile.setVisibility(View.VISIBLE);
@ -911,7 +903,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false);
CrossActions.doCrossAction(context, status, API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false);
return true;
}
});
@ -919,19 +911,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false);
CrossActions.doCrossAction(context, status, API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false);
return true;
}
});
holder.status_pin.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true);
return false;
}
});
holder.yandex_translate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View File

@ -72,6 +72,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private boolean showMediaOnly, showPinned;
private Intent streamingFederatedIntent, streamingLocalIntent;
LinearLayoutManager mLayoutManager;
boolean firstTootsLoaded;
public DisplayStatusFragment(){
}
@ -83,6 +84,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
context = getContext();
Bundle bundle = this.getArguments();
showMediaOnly = false;
//Will allow to load first toots if bookmark != null
firstTootsLoaded = true;
showPinned = false;
if (bundle != null) {
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
@ -95,7 +98,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
flag_loading = true;
firstLoad = true;
swiped = false;
assert context != null;
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(context);
@ -117,10 +119,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(dy > 0){
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if(!flag_loading ) {
flag_loading = true;
@ -137,6 +139,14 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
nextElementLoader.setVisibility(View.GONE);
}
}
if(statuses != null && statuses.size() > firstVisibleItem )
if( context instanceof BaseMainActivity){
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Long bookmarkL = Long.parseLong(statuses.get(firstVisibleItem).getId()) + 1;
editor.putString(Helper.BOOKMARK_ID + userId, String.valueOf(bookmarkL));
editor.apply();
}
}
});
@ -169,16 +179,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else {
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( type == RetrieveFeedsAsyncTask.Type.HOME ){
String bookmark;
if( context instanceof BaseMainActivity){
bookmark = ((BaseMainActivity) context).getBookmark();
if( bookmark != null) {
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, bookmark,null, false,false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, bookmark, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
firstTootsLoaded = false;
}
}
}else {
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}else {
@ -191,16 +202,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else {
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( type == RetrieveFeedsAsyncTask.Type.HOME ){
String bookmark;
if( context instanceof BaseMainActivity){
bookmark = ((BaseMainActivity) context).getBookmark();
if( bookmark != null) {
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, bookmark,null, false,false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, bookmark, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
firstTootsLoaded = false;
}
}
}else {
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
@ -252,8 +264,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
int previousPosition = this.statuses.size();
List<Status> statuses = apiResponse.getStatuses();
max_id = apiResponse.getMax_id();
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
if (max_id == null || (apiResponse.getMax_id() != null && Long.parseLong(max_id) > Long.parseLong(apiResponse.getMax_id())))
max_id = apiResponse.getMax_id();
}else {
max_id = apiResponse.getMax_id();
}
flag_loading = (max_id == null );
if( !swiped && firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
@ -269,50 +285,48 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
swiped = false;
}
//First toot are loaded as soon as the bookmark has been retrieved
if( type == RetrieveFeedsAsyncTask.Type.HOME && !firstTootsLoaded){
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
firstTootsLoaded = true;
}
if( statuses != null && statuses.size() > 0) {
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
String bookmark = null;
if( context instanceof BaseMainActivity){
bookmark = ((BaseMainActivity) context).getBookmark();
}
//Toots are older than the bookmark -> no special treatment with them
if( bookmark == null || Long.parseLong(statuses.get(0).getId()) < Long.parseLong(bookmark)){
if( bookmark == null || Long.parseLong(statuses.get(0).getId())+1 < Long.parseLong(bookmark)){
this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
}else { //Toots are younger than the bookmark
int lastLoop = 0;
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
int position = 0;
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
position++;
}
ArrayList<Status> tmpStatuses = new ArrayList<>();
for (Status tmpStatus : statuses) {
//Mark status at new ones when their id is greater than the bookmark id / Also increments counter
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark)) {
if (currentMaxId != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(currentMaxId)) {
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}
//Put the toot at its place in the list (id desc)
if (this.statuses != null) {
int loop = 0;
while (loop < this.statuses.size() && Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(loop).getId())) {
loop++;
}
if(Long.parseLong(statuses.get(0).getId()) != Long.parseLong(bookmark) ) {
if( !this.statuses.contains(tmpStatus) ) { //Element not already addeds
this.statuses.add(loop, tmpStatus);
statusListAdapter.notifyItemInserted(loop);
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark) && loop > lastLoop)
lastLoop = loop; //Record the last position of the inserted toot in this.statuses
}
}
if( !this.statuses.contains(tmpStatus) ) { //Element not already addeds
tmpStatuses.add(tmpStatus);
}
}
if (tmpStatuses.size() > 0 && Long.parseLong(tmpStatuses.get(tmpStatuses.size()-1).getId()) > Long.parseLong(bookmark)) {
tmpStatuses.get(tmpStatuses.size()-1).setFetchMore(true);
}
if (Long.parseLong(statuses.get((statuses.size() - 1)).getId()) > Long.parseLong(bookmark)) {
statuses.get(statuses.size() - 1).setFetchMore(true);
}
if( lastLoop > 0 ) //Moves to the bookmark
lv_status.scrollToPosition((lastLoop));
this.statuses.addAll(position, tmpStatuses);
statusListAdapter.notifyItemRangeInserted(position, tmpStatuses.size());
lv_status.scrollToPosition(position+tmpStatuses.size());
}
}else {
@ -322,12 +336,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
//Update the id of the last toot retrieved
MainActivity.lastHomeId = statuses.get(0).getId();
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.apply();
updateMaxId(statuses.get(0).getId());
}
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME)
if( type == RetrieveFeedsAsyncTask.Type.HOME)
//Display new value in counter
try {
((MainActivity) context).updateHomeCounter();
@ -442,11 +453,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
return;
//Store last toot id for home timeline to avoid to notify for those that have been already seen
if (type == RetrieveFeedsAsyncTask.Type.HOME && visible && statuses != null && statuses.size() > 0) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.apply();
updateMaxId(statuses.get(0).getId());
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
if (visible) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -517,11 +524,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
lv_status.setAdapter(statusListAdapter);
//Store last toot id for home timeline to avoid to notify for those that have been already seen
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > 0) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.apply();
updateMaxId(statuses.get(0).getId());
}
}
}
@ -557,4 +560,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public void fetchMore(String max_id){
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void updateMaxId(String max_id){
if( max_id == null)
return;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
if( currentMaxId == null || Long.parseLong(max_id) > Long.parseLong(currentMaxId)) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, max_id);
editor.apply();
}
}
}

View File

@ -216,6 +216,19 @@ public class SettingsFragment extends Fragment {
}
});
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
final CheckBox set_disable_gif = rootView.findViewById(R.id.set_disable_gif);
set_disable_gif.setChecked(disableGif);
set_disable_gif.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISABLE_GIF, set_disable_gif.isChecked());
editor.apply();
}
});
boolean livenotif = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
final CheckBox set_live_notif = rootView.findViewById(R.id.set_live_notify);
set_live_notif.setChecked(livenotif);
@ -235,6 +248,7 @@ public class SettingsFragment extends Fragment {
});
boolean display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true);
final CheckBox set_display_global = rootView.findViewById(R.id.set_display_global);
set_display_global.setChecked(display_global);

View File

@ -180,6 +180,8 @@ public class Helper {
public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message";
public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id";
public static final String LAST_HOMETIMELINE_MAX_ID = "last_hometimeline_max_id";
public static final String BOOKMARK_ID = "bookmark_id";
public static final String LAST_HOMETIMELINE_NOTIFICATION_MAX_ID = "last_hometimeline_notification_max_id";
public static final String SHOULD_CONTINUE_STREAMING = "should_continue_streaming";
public static final String SHOULD_CONTINUE_STREAMING_FEDERATED = "should_continue_streaming_federated";
public static final String SHOULD_CONTINUE_STREAMING_LOCAL = "should_continue_streaming_local";
@ -214,6 +216,7 @@ public class Helper {
public static final String INSTANCE_VERSION = "instance_version";
public static final String SET_LIVE_NOTIFICATIONS = "set_show_replies";
public static final String SET_PICTURE_URL = "set_picture_url";
public static final String SET_DISABLE_GIF = "set_disable_gif";
public static final int ATTACHMENT_ALWAYS = 1;
public static final int ATTACHMENT_WIFI = 2;
public static final int ATTACHMENT_ASK = 3;
@ -574,8 +577,11 @@ public class Helper {
return context.getResources().getQuantityString(R.plurals.date_hours, (int)hours, (int)hours);
else if(minutes > 0)
return context.getResources().getQuantityString(R.plurals.date_minutes, (int)minutes, (int)minutes);
else
return context.getResources().getQuantityString(R.plurals.date_seconds, (int)seconds, (int)seconds);
else {
if (seconds < 0)
seconds = 0;
return context.getResources().getQuantityString(R.plurals.date_seconds, (int) seconds, (int) seconds);
}
}
/***
@ -1669,4 +1675,26 @@ public class Helper {
return output;
}
public static void loadGiF(final Context context, String url, final ImageView imageView){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
if( !disableGif)
Glide.with(imageView.getContext())
.load(url)
.into(imageView);
else
Glide.with(context)
.asBitmap()
.load(url)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
imageView.setImageBitmap(resource);
}
});
}
}

View File

@ -69,7 +69,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
@NonNull
@Override
protected Result onRunJob(Params params) {
protected Result onRunJob(@NonNull Params params) {
callAsynchronousTask();
return Result.SUCCESS;
}
@ -117,8 +117,17 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
return;
//Retrieve users in db that owner has.
for (Account account: accounts) {
String since_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getId(), null);
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account.getInstance(), account.getToken(), since_id, account.getAcct(), account.getId(), HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId(), null);
String lastHomeSeen = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getId(), null);
if( lastHomeSeen != null && max_id != null){
if( Long.parseLong(lastHomeSeen) > Long.parseLong(max_id)){
max_id = lastHomeSeen;
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId(), max_id);
editor.apply();
}
}
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@ -132,7 +141,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
return;
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
final String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, null);
//No previous notifications in cache, so no notification will be sent
String message;
@ -179,7 +188,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
notify_user(getContext(), intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.mastodonlogo), finalTitle, finalMessage);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, statuses.get(0).getId());
editor.apply();
return false;
}
@ -189,7 +198,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
notify_user(getContext(), intent, notificationId, resource, finalTitle, finalMessage);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, statuses.get(0).getId());
editor.apply();
}
});

View File

@ -1,9 +0,0 @@
<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="#FFFFFFFF"
android:pathData="M20,5h-9.12L10,2L4,2c-1.1,0 -2,0.9 -2,2v13c0,1.1 0.9,2 2,2h7l1,3h8c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM7.17,14.59c-2.25,0 -4.09,-1.83 -4.09,-4.09s1.83,-4.09 4.09,-4.09c1.04,0 1.99,0.37 2.74,1.07l0.07,0.06 -1.23,1.18 -0.06,-0.05c-0.29,-0.27 -0.78,-0.59 -1.52,-0.59 -1.31,0 -2.38,1.09 -2.38,2.42s1.07,2.42 2.38,2.42c1.37,0 1.96,-0.87 2.12,-1.46L7.08,11.46L7.08,9.91h3.95l0.01,0.07c0.04,0.21 0.05,0.4 0.05,0.61 0,2.35 -1.61,4 -3.92,4zM13.2,12.88c0.33,0.6 0.74,1.18 1.19,1.7l-0.54,0.53 -0.65,-2.23zM13.97,12.12h-0.99l-0.31,-1.04h3.99s-0.34,1.31 -1.56,2.74c-0.52,-0.62 -0.89,-1.23 -1.13,-1.7zM21,20c0,0.55 -0.45,1 -1,1h-7l2,-2 -0.81,-2.77 0.92,-0.92L17.79,18l0.73,-0.73 -2.71,-2.68c0.9,-1.03 1.6,-2.25 1.92,-3.51L19,11.08v-1.04h-3.64L15.36,9h-1.04v1.04h-1.96L11.18,6L20,6c0.55,0 1,0.45 1,1v13z"/>
</vector>

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="#FFFFFFFF"
android:pathData="M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"/>
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 B

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 B

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 554 B

After

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 823 B

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 939 B

After

Width:  |  Height:  |  Size: 894 B

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>

View File

@ -53,11 +53,13 @@
app:layout_collapseMode="parallax"
tools:ignore="ContentDescription" />
<ImageView
android:padding="10dp"
android:padding="1dp"
android:layout_margin="10dp"
android:id="@+id/account_pp"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_width="130dp"
android:layout_height="130dp"
app:layout_scrollFlags="scroll"
android:background="@drawable/circle_background_white"
android:layout_centerInParent="true"
tools:ignore="ContentDescription" />
<android.support.design.widget.FloatingActionButton

View File

@ -119,6 +119,14 @@
android:text="@string/live_notif"
android:layout_height="wrap_content" />
<!-- GIF AVATARS -->
<CheckBox
android:id="@+id/set_disable_gif"
android:layout_width="wrap_content"
android:text="@string/set_disable_gif"
android:layout_height="wrap_content" />
<!-- TABS Layout -->
<LinearLayout
android:id="@+id/translation_layout_container"

View File

@ -52,11 +52,13 @@
app:layout_collapseMode="parallax"
tools:ignore="ContentDescription" />
<ImageView
android:padding="10dp"
android:padding="1dp"
android:layout_margin="10dp"
android:id="@+id/account_pp"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_width="130dp"
android:layout_height="130dp"
app:layout_scrollFlags="scroll"
android:background="@drawable/circle_background_white"
android:layout_centerInParent="true"
tools:ignore="ContentDescription" />
<android.support.design.widget.FloatingActionButton

View File

@ -120,6 +120,14 @@
android:text="@string/live_notif"
android:layout_height="wrap_content" />
<!-- GIF AVATARS -->
<CheckBox
android:id="@+id/set_disable_gif"
android:layout_width="wrap_content"
android:text="@string/set_disable_gif"
android:layout_height="wrap_content" />
<!-- Translation engine -->
<LinearLayout
android:layout_marginTop="10dp"

View File

@ -19,7 +19,7 @@
<item
android:id="@+id/action_translate"
android:title="@string/translate"
android:icon="@drawable/ic_g_translate"
android:icon="@drawable/ic_translate"
app:showAsAction="never" />
<item
android:id="@+id/action_store"

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -444,4 +444,5 @@
<string name="search">البحث</string>
<string name="delete">حذف</string>
<string name="fetch_more_toots">تحميل المزيد من التبويقات ...</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -422,4 +422,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -403,4 +403,5 @@
<string name="search">Suche</string>
<string name="delete">Löschen</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -413,4 +413,5 @@
<string name="search">Rechercher</string>
<string name="delete">Supprimer</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -430,4 +430,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -407,4 +407,5 @@ https://yandex.ru/legal/confidential/?lang=en
<string name="search">Cari</string>
<string name="delete">Hapus</string>
<string name="fetch_more_toots">Ambil lebih banyak kutipan…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -406,4 +406,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -406,4 +406,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Zoeken</string>
<string name="delete">Verwijderen</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -422,4 +422,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -414,4 +414,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -417,5 +417,6 @@ Vă mulțumesc:
<string name="filter_regex">Filtrează expresii usuale</string>
<string name="search">Căutare</string>
<string name="delete">Șterge</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -421,5 +421,6 @@
<string name="filter_regex">Filter out by regular expressions</string>
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -421,5 +421,6 @@
<string name="filter_regex">Filter out by regular expressions</string>
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -413,5 +413,6 @@
<string name="filter_regex">Filter out by regular expressions</string>
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -405,5 +405,6 @@ Teşekkürler: </string>
<string name="filter_regex">Düzenli ifadelerle filtreleme</string>
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -421,5 +421,6 @@
<string name="filter_regex">Filter out by regular expressions</string>
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -405,4 +405,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -398,4 +398,5 @@
<string name="search">Search</string>
<string name="delete">Delete</string>
<string name="fetch_more_toots">Fetch more toots…</string>
<string name="set_disable_gif">Disable GIF avatars</string>
</resources>

View File

@ -300,6 +300,7 @@
<string name="set_display_reply">Display previous message in responses</string>
<string name="set_display_local">Display local timeline</string>
<string name="set_display_global">Display federated timeline</string>
<string name="set_disable_gif">Disable GIF avatars</string>
<string name="set_folder_title">Path: </string>
<string name="set_auto_store_toot">Save drafts automatically</string>
<string name="set_bubble_counter">Display counters</string>

View File

@ -14,14 +14,16 @@
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
/**
* Created by Thomas on 23/04/2017.
* Login activity class which handles the connection
*/
public class LoginActivity extends BaseLoginActivity {
import com.kobakei.ratethisapp.RateThisApp;
public class MainActivity extends BaseMainActivity {
@Override
protected void installProviders() {
// do nothing
protected void rateThisApp() {
RateThisApp.onCreate(this);
RateThisApp.showRateDialogIfNeeded(this);
}
}
}

View File

@ -1,82 +0,0 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastalab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.content.DialogInterface;
import android.content.Intent;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller;
/**
* Created by Thomas on 23/04/2017.
* Login activity class which handles the connection
*/
public class LoginActivity extends BaseLoginActivity implements ProviderInstaller.ProviderInstallListener {
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
@Override
protected void installProviders() {
ProviderInstaller.installIfNeededAsync(this, this);
}
@Override
public void onProviderInstalled() {
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
// Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment
// before the instance state is restored throws an error. So instead,
// set a flag here, which will cause the fragment to delay until
// onPostResume.
}
}
@Override
public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
// Recoverable error. Show a dialog prompting the user to
// install/update/enable Google Play services.
GooglePlayServicesUtil.showErrorDialogFragment(
errorCode,
this,
ERROR_DIALOG_REQUEST_CODE,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// The user chose not to take the recovery action
onProviderInstallerNotAvailable();
}
});
} else {
// Google Play services is not available.
onProviderInstallerNotAvailable();
}
}
private void onProviderInstallerNotAvailable() {
// This is reached if the provider cannot be updated for some reason.
// App should consider all HTTP communication to be vulnerable, and take
// appropriate action.
}
}

View File

@ -1,85 +0,0 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastalab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.content.DialogInterface;
import android.content.Intent;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller;
import com.kobakei.ratethisapp.RateThisApp;
public class MainActivity extends BaseMainActivity
implements ProviderInstaller.ProviderInstallListener {
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
@Override
protected void rateThisApp() {
RateThisApp.onCreate(this);
RateThisApp.showRateDialogIfNeeded(this);
}
@Override
protected void installProviders() {
ProviderInstaller.installIfNeededAsync(this, this);
}
@Override
public void onProviderInstalled() {
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
// Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment
// before the instance state is restored throws an error. So instead,
// set a flag here, which will cause the fragment to delay until
// onPostResume.
}
}
@Override
public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
// Recoverable error. Show a dialog prompting the user to
// install/update/enable Google Play services.
GooglePlayServicesUtil.showErrorDialogFragment(
errorCode,
this,
ERROR_DIALOG_REQUEST_CODE,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// The user chose not to take the recovery action
onProviderInstallerNotAvailable();
}
});
} else {
// Google Play services is not available.
onProviderInstallerNotAvailable();
}
}
private void onProviderInstallerNotAvailable() {
// This is reached if the provider cannot be updated for some reason.
// App should consider all HTTP communication to be vulnerable, and take
// appropriate action.
}
}