Fixes bug when the token has changed + error with downloads

This commit is contained in:
tom79 2017-05-16 19:41:25 +02:00
parent 78d684e710
commit 1cb118d99f
3 changed files with 33 additions and 15 deletions

View File

@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
targetSdkVersion 25
versionCode 2
versionName "1.0.3"
versionCode 3
versionName "1.0.3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@ -38,6 +38,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
@ -131,7 +132,7 @@ public class MainActivity extends AppCompatActivity
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
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);
TextView username = (TextView) headerLayout.findViewById(R.id.username);
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 ownerFollowers = (TextView) headerLayout.findViewById(R.id.owner_followers);
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);
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
//Something wrong happened with the account recorded in db (ie: bad token)
if( account == null ) {
Helper.logout(getApplicationContext());
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
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;
if( getIntent() != null && getIntent().getExtras() != null ){
Bundle extras = getIntent().getExtras();

View File

@ -19,10 +19,8 @@ package fr.gouv.etalab.mastodon.helper;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
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){
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
final DownloadManager.Request request;
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);
File f = new File("" + uri);
final String fileName = f.getName();