Merged in develop (pull request #2)

This commit is contained in:
tom79 2017-05-16 17:58:31 +00:00
commit 8a1ab11280
4 changed files with 41 additions and 17 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 4
versionName "1.0.4"
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

@ -493,16 +493,21 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
break;
}
}
String urlDownload = attachment.getRemote_url();
if( urlDownload == null || urlDownload.trim().equals(""))
urlDownload = attachment.getUrl();
final String finalUrlDownload = urlDownload;
alertadd.setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
if(Build.VERSION.SDK_INT >= 23 ){
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions((MainActivity)context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(context, attachment.getRemote_url());
Helper.manageDownloads(context, finalUrlDownload);
}
}else{
Helper.manageDownloads(context, attachment.getRemote_url());
Helper.manageDownloads(context, finalUrlDownload);
}
dlg.dismiss();
}

View File

@ -19,16 +19,15 @@ 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;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
@ -324,11 +323,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();