diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/StoredStatus.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/StoredStatus.java index d1ebb1e5b..5e65cc5fc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/StoredStatus.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/StoredStatus.java @@ -18,7 +18,7 @@ public class StoredStatus { private boolean isSent; private Status status; private String instance; - private String acct; + private String userId; public int getId() { return id; @@ -77,14 +77,6 @@ public class StoredStatus { this.instance = instance; } - public String getAcct() { - return acct; - } - - public void setAcct(String acct) { - this.acct = acct; - } - public int getJobId() { return jobId; } @@ -92,4 +84,12 @@ public class StoredStatus { public void setJobId(int jobId) { this.jobId = jobId; } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java index caa523923..4f22bedb6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java @@ -173,7 +173,7 @@ public class ScheduledTootsListAdapter extends BaseAdapter { } }); if( job == null){ - holder.scheduled_toot_failed.setVisibility(View.VISIBLE); + holder.scheduled_toot_failed.setVisibility(View.GONE); }else { holder.scheduled_toot_failed.setVisibility(View.GONE); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 62356da80..430ffbdf6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -168,7 +168,7 @@ public class SettingsFragment extends Fragment { }else { set_cookies_container.setVisibility(View.GONE); } - final String targeted_folder = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS); + final String targeted_folder = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()); set_folder = (TextView) rootView.findViewById(R.id.set_folder); set_folder.setText(targeted_folder); @@ -217,7 +217,7 @@ public class SettingsFragment extends Fragment { DocumentsContract.getTreeDocumentId(treeUri)); String path = getPath(context, docUri); if( path == null ) - path = Environment.DIRECTORY_DOWNLOADS; + path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.SET_FOLDER_RECORD, path); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index fcab27bb2..66b1ccf8d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -79,6 +79,7 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -573,18 +574,22 @@ public class Helper { public static void manageMoveFileDownload(final Context context, final String preview_url, final String url, Bitmap bitmap, File fileVideo){ final String fileName = URLUtil.guessFileName(url, null, null);final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS); + String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()); try { File file; if( bitmap != null) { - File filebmp = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName); - FileOutputStream out = new FileOutputStream(filebmp); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); - out.flush(); - out.close(); file = new File(myDir, fileName); - copy(filebmp, file); + file.createNewFile(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); + byte[] bitmapdata = bos.toByteArray(); + + FileOutputStream fos = new FileOutputStream(file); + fos.write(bitmapdata); + fos.flush(); + fos.close(); }else{ File fileVideoTargeded = new File(myDir, fileName); copy(fileVideo, fileVideoTargeded); @@ -594,7 +599,6 @@ public class Helper { final int notificationIdTmp = r.nextInt(10000); // prepare intent which is triggered if the // notification is selected - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); final Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.parse("file://" + file.getAbsolutePath()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/ScheduledTootsSyncJob.java b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/ScheduledTootsSyncJob.java index fde68a5c9..e6583f1c4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/ScheduledTootsSyncJob.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/ScheduledTootsSyncJob.java @@ -23,8 +23,10 @@ import java.util.Date; import java.util.concurrent.TimeUnit; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.client.Entities.StoredStatus; +import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; @@ -36,8 +38,7 @@ import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; public class ScheduledTootsSyncJob extends Job { - public static final String SCHEDULED_TOOT = "job_scheduled_toot"; - + static final String SCHEDULED_TOOT = "job_scheduled_toot"; @NonNull @Override @@ -45,16 +46,23 @@ public class ScheduledTootsSyncJob extends Job { //Code refresh here int jobId = params.getId(); SQLiteDatabase db = Sqlite.getInstance(getContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - StoredStatus storedStatus = new StatusStoredDAO(getContext(), db).getStatusScheduled(jobId); //Retrieves the stored status + StoredStatus storedStatus = new StatusStoredDAO(getContext(), db).getStatusScheduled(jobId); if( storedStatus != null){ - //Retrieves the linked status to toot - Status status = storedStatus.getStatus(); - if( status != null){ - int statusCode = new API(getContext()).statusAction(status); - //Toot was sent - if( statusCode == 200){ - new StatusStoredDAO(getContext(), db).updateScheduledDone(jobId, new Date()); + String userId = storedStatus.getUserId(); + String instance = storedStatus.getInstance(); + if( instance != null && userId != null){ + Account account = new AccountDAO(getContext(), db).getAccountByUserIDInstance(userId, instance); + if( account != null){ + //Retrieves the linked status to toot + Status status = storedStatus.getStatus(); + if( status != null){ + int statusCode = new API(getContext(), account.getInstance(), account.getToken()).statusAction(status); + //Toot was sent + if( statusCode == 200){ + new StatusStoredDAO(getContext(), db).updateScheduledDone(jobId, new Date()); + } + } } } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java index cf5e3988a..e0aab8554 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java @@ -133,6 +133,21 @@ public class AccountDAO { } } + /** + * Returns an Account by id and instance + * @param accountId String + * @param instance String + * @return Account + */ + public Account getAccountByUserIDInstance(String accountId, String instance){ + try { + Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_USER_ID + " = '" + accountId + "' AND " + Sqlite.COL_INSTANCE + "= '"+ Sqlite.COL_INSTANCE +"'", null, null, null, null, "1"); + return cursorToUser(c); + } catch (Exception e) { + return null; + } + } + /** * Returns all Account in db * @return Account List