Fixes bug when the token has changed + error with downloads
This commit is contained in:
parent
78d684e710
commit
1cb118d99f
|
@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion 25
|
||||||
buildToolsVersion "25.0.2"
|
buildToolsVersion "25.0.3"
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "fr.gouv.etalab.mastodon"
|
applicationId "fr.gouv.etalab.mastodon"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 2
|
versionCode 3
|
||||||
versionName "1.0.3"
|
versionName "1.0.3.1"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
|
@ -131,7 +132,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
|
||||||
ImageView profilePicture = (ImageView) headerLayout.findViewById(R.id.profilePicture);
|
ImageView profilePicture = (ImageView) headerLayout.findViewById(R.id.profilePicture);
|
||||||
TextView username = (TextView) headerLayout.findViewById(R.id.username);
|
TextView username = (TextView) headerLayout.findViewById(R.id.username);
|
||||||
TextView displayedName = (TextView) headerLayout.findViewById(R.id.displayedName);
|
TextView displayedName = (TextView) headerLayout.findViewById(R.id.displayedName);
|
||||||
|
@ -139,13 +140,22 @@ public class MainActivity extends AppCompatActivity
|
||||||
TextView ownerFollowing = (TextView) headerLayout.findViewById(R.id.owner_following);
|
TextView ownerFollowing = (TextView) headerLayout.findViewById(R.id.owner_following);
|
||||||
TextView ownerFollowers = (TextView) headerLayout.findViewById(R.id.owner_followers);
|
TextView ownerFollowers = (TextView) headerLayout.findViewById(R.id.owner_followers);
|
||||||
|
|
||||||
ownerStatus.setText(String.valueOf(account.getStatuses_count()));
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
||||||
ownerFollowers.setText(String.valueOf(account.getFollowers_count()));
|
//Something wrong happened with the account recorded in db (ie: bad token)
|
||||||
ownerFollowing.setText(String.valueOf(account.getFollowing_count()));
|
if( account == null ) {
|
||||||
username.setText(String.format("@%s",account.getUsername()));
|
Helper.logout(getApplicationContext());
|
||||||
displayedName.setText(account.getDisplay_name());
|
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
|
||||||
imageLoader.displayImage(account.getAvatar(), profilePicture, options);
|
Toast.makeText(getApplicationContext(),R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||||
|
startActivity(myIntent);
|
||||||
|
finish(); //User is logged out to get a new token
|
||||||
|
}else {
|
||||||
|
ownerStatus.setText(String.valueOf(account.getStatuses_count()));
|
||||||
|
ownerFollowers.setText(String.valueOf(account.getFollowers_count()));
|
||||||
|
ownerFollowing.setText(String.valueOf(account.getFollowing_count()));
|
||||||
|
username.setText(String.format("@%s",account.getUsername()));
|
||||||
|
displayedName.setText(account.getDisplay_name());
|
||||||
|
imageLoader.displayImage(account.getAvatar(), profilePicture, options);
|
||||||
|
}
|
||||||
boolean menuWasSelected = false;
|
boolean menuWasSelected = false;
|
||||||
if( getIntent() != null && getIntent().getExtras() != null ){
|
if( getIntent() != null && getIntent().getExtras() != null ){
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
|
|
|
@ -19,10 +19,8 @@ package fr.gouv.etalab.mastodon.helper;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
@ -324,11 +322,21 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage downloads with URLs
|
||||||
|
* @param context Context
|
||||||
|
* @param url String download url
|
||||||
|
*/
|
||||||
public static void manageDownloads(final Context context, final String url){
|
public static void manageDownloads(final Context context, final String url){
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
final DownloadManager.Request request;
|
||||||
final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
try {
|
||||||
|
request = new DownloadManager.Request(Uri.parse(url.trim()));
|
||||||
|
}catch (Exception e){
|
||||||
|
Toast.makeText(context,R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
File f = new File("" + uri);
|
File f = new File("" + uri);
|
||||||
final String fileName = f.getName();
|
final String fileName = f.getName();
|
||||||
|
|
Loading…
Reference in New Issue