Merged in develop (pull request #28)

This commit is contained in:
tom79 2017-07-18 17:58:26 +00:00
commit c33c1df17d
19 changed files with 284 additions and 107 deletions

View File

@ -1,7 +1,62 @@
**Mastalab** est une application Android multi-comptes pour Mastodon
<b>Mastalab is a multi-accounts client for Mastodon</b>
The number of libraries is minimized and it does not use tracking tools. The source code is free (GPLv3). Any help would be greatly appreciated to fix spelling or for any other suggestions.
**Features**
<b>Multi-accounts management</b>
- Add accounts from different instances
- Switch from one account to another by a simple click
<b>Timelines</b>
- Federated / Local / Home
- Switch from one timeline to another by using the menu or by swiping the screen.
- Clicks on toots display the related conversations (context)
- Clicks on mentioned accounts display details about these accounts
- Clicks on hashtags display toots containing this hashtags
<b>Actions on toots</b>
- Mute an account related to a toot
- Block an account related to a toot
- Report inappropriate toots to administrators
- Add/Remove a toot from favourites
- Boost/Unboost toots
- Copy the content of a toot
- Download media
- Translation of toots by a simple click (via the Yandex API)
<b>Write a toot</b>
- Add media
- Change the visibility of the toot
- Mention accounts in toots with autocompletion (@ + 2 characters)
- Mark the content as sensitive
- Add spoilers
<b>Interaction with accounts</b>
- Follow/Unfollow/Block/Unblock/Mute/Unmute
- Display details of accounts
- Authorize/Reject follow requests (for locked accounts)
<b>Searches</b>
- A top bar allows to make researches for accounts/tags/toots
- A click on a tag displays toots containing this tag
<b>Network optimization</b>
- Load of media: Automatic/WIFI only/Ask
- Customization of the number of toots/accounts per load
<b>Notifications</b>
- Notifications for new toots on the home page (could be disabled in settings)
- Notifications for new events (could be disabled or filtered in settings)
<b>Built-in browser</b>
- Full screen videos
- Disable JavaScript (default: enabled)
- Disable third-party cookies (default: disabled)
- Disable the built-in browser in settings
Pour toute remarque ou demande d'évolution, vous pouvez me contacter sur cette instance : [@tschneider](https://mastodon.etalab.gouv.fr/@tschneider)
Developer: [@tschneider](https://mastodon.etalab.gouv.fr/@tschneider)

View File

@ -7,8 +7,8 @@ android {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
targetSdkVersion 25
versionCode 30
versionName "1.3.3"
versionCode 31
versionName "1.3.4"
}
buildTypes {
release {

Binary file not shown.

View File

@ -14,6 +14,7 @@ package fr.gouv.etalab.mastodon.activities;
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Application;
import android.os.StrictMode;
import com.evernote.android.job.JobManager;
@ -36,5 +37,8 @@ public class MainApplication extends Application{
JobManager.instance().getConfig().setVerbose(false);
NotificationsSyncJob.schedule(false);
HomeTimelineSyncJob.schedule(false);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
}

View File

@ -34,7 +34,6 @@ import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -60,7 +59,6 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
@ -97,7 +95,6 @@ import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
/**
* Created by Thomas on 01/05/2017.
* Toot activity class
@ -121,6 +118,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private ImageButton toot_visibility;
private Button toot_it;
private EditText toot_content, toot_cw_content;
private TextView toot_reply_content;
private LinearLayout toot_reply_content_container;
private RelativeLayout toot_show_accounts;
private ListView toot_lv_accounts;
@ -132,6 +130,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private long restored;
private String pattern = "^.*(@([a-zA-Z0-9_]{2,}))$";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -161,34 +160,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_picture_container = (LinearLayout) findViewById(R.id.toot_picture_container);
toot_content = (EditText) findViewById(R.id.toot_content);
toot_cw_content = (EditText) findViewById(R.id.toot_cw_content);
TextView toot_reply_content = (TextView) findViewById(R.id.toot_reply_content);
toot_reply_content = (TextView) findViewById(R.id.toot_reply_content);
toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container);
toot_show_accounts = (RelativeLayout) findViewById(R.id.toot_show_accounts);
toot_lv_accounts = (ListView) findViewById(R.id.toot_lv_accounts);
toot_sensitive = (CheckBox) findViewById(R.id.toot_sensitive);
if( theme == Helper.THEME_DARK){
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_camera,R.color.dark_text);
}else {
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_camera,R.color.black);
}
final LinearLayout drawer_layout = (LinearLayout) findViewById(R.id.drawer_layout);
drawer_layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
@ -220,53 +199,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
invalidateOptionsMenu();
}
if( tootReply != null) {
setTitle(R.string.toot_title_reply);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
if( show_reply ){
toot_reply_content_container.setVisibility(View.VISIBLE);
}else {
toot_reply_content_container.setVisibility(View.GONE);
}
String content = tootReply.getContent();
if(tootReply.getReblog() != null)
content = tootReply.getReblog().getContent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
toot_reply_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
else
//noinspection deprecation
toot_reply_content.setText(Html.fromHtml(content));
switch (tootReply.getVisibility()){
case "public":
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_action_globe);
break;
case "unlisted":
visibility = "unlisted";
toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
break;
case "private":
visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
break;
case "direct":
visibility = "direct";
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
break;
}
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot
if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) {
toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct()));
}
if( tootReply.getMentions() != null ){
for(Mention mention : tootReply.getMentions()){
if( mention.getAcct() != null && !mention.getId().equals(userId)) {
String tootTemp = String.format("@%s ", mention.getAcct());
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp)));
}
}
}
toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end
tootReply();
}else {
setTitle(R.string.toot_title);
}
@ -304,7 +237,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
};
LocalBroadcastManager.getInstance(this).registerReceiver(search_validate, new IntentFilter(Helper.SEARCH_VALIDATE_ACCOUNT));
FloatingActionButton toot_close_accounts = (FloatingActionButton) findViewById(R.id.toot_close_accounts);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
@ -331,8 +263,10 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
}else {
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_action_globe);
if( tootReply == null){
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_action_globe);
}
}
toot_sensitive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@ -364,7 +298,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
});
toot_it.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -463,6 +396,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
if( restored != -1 ){
restoreToot(restored);
}
changeColor();
}
@ -488,7 +422,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
}else if(requestCode == Helper.REQ_CODE_SPEECH_INPUT && resultCode == Activity.RESULT_OK){
if (null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
toot_content.setText(result.get(0));
@ -590,17 +523,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.datetime_picker, null);
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_DARK){
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_previous,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_next,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_check,R.color.dark_text);
}else {
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_previous,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_next,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_check,R.color.black);
}
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog = dialogBuilder.create();
@ -686,7 +608,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
}
});
changeColor();
alertDialog.show();
return true;
default:
@ -713,6 +635,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(search_validate);
}
@Override
public void onRetrieveAttachment(final Attachment attachment, Error error) {
loading_picture.setVisibility(View.GONE);
@ -794,7 +717,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private void tootVisibilityDialog(){
AlertDialog.Builder dialog = new AlertDialog.Builder(TootActivity.this);
dialog.setTitle(R.string.toot_visibility_tilte);
final String[] stringArray = getResources().getStringArray(R.array.toot_visibility);
@ -826,6 +748,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
break;
}
changeColor();
dialog.dismiss();
}
});
@ -899,6 +822,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
StoredStatus draft = new StatusStoredDAO(TootActivity.this, db).getStatus(id);
Status status = draft.getStatus();
//Retrieves attachments
restored = id;
attachments = status.getMedia_attachments();
toot_picture_container.removeAllViews();
loading_picture.setVisibility(View.GONE);
@ -962,11 +886,75 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
break;
}
changeColor();
//The current id is set to the draft
currentToId = draft.getId();
tootReply = draft.getStatusReply();
if( tootReply != null) {
tootReply();
}else {
setTitle(R.string.toot_title);
}
}
private void tootReply(){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
setTitle(R.string.toot_title_reply);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
if( show_reply ){
toot_reply_content_container.setVisibility(View.VISIBLE);
}else {
toot_reply_content_container.setVisibility(View.GONE);
}
String content = tootReply.getContent();
if(tootReply.getReblog() != null)
content = tootReply.getReblog().getContent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
toot_reply_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
else
//noinspection deprecation
toot_reply_content.setText(Html.fromHtml(content));
switch (tootReply.getVisibility()){
case "public":
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_action_globe);
break;
case "unlisted":
visibility = "unlisted";
toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
break;
case "private":
visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
break;
case "direct":
visibility = "direct";
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
break;
}
changeColor();
//If toot is not restored
if( restored == -1 ){
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot
if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) {
toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct()));
}
if( tootReply.getMentions() != null ){
for(Mention mention : tootReply.getMentions()){
if( mention.getAcct() != null && !mention.getId().equals(userId)) {
String tootTemp = String.format("@%s ", mention.getAcct());
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp)));
}
}
}
toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end
}
}
private void storeToot(boolean message){
//Nothing to store here....
if(toot_content.getText().toString().trim().length() == 0 && (attachments == null || attachments.size() <1) && toot_cw_content.getText().toString().trim().length() == 0)
@ -984,14 +972,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
try{
if( currentToId == -1 ) {
currentToId = new StatusStoredDAO(TootActivity.this, db).insertStatus(toot);
currentToId = new StatusStoredDAO(TootActivity.this, db).insertStatus(toot, tootReply);
}else{
StoredStatus storedStatus = new StatusStoredDAO(TootActivity.this, db).getStatus(currentToId);
if( storedStatus != null ){
new StatusStoredDAO(TootActivity.this, db).updateStatus(currentToId, toot);
}else { //Might have been deleted, so it needs insertion
new StatusStoredDAO(TootActivity.this, db).insertStatus(toot);
new StatusStoredDAO(TootActivity.this, db).insertStatus(toot, tootReply);
}
}
if( message )
@ -1002,4 +990,29 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
}
private void changeColor(){
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_DARK){
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_camera,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_previous,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_next,R.color.dark_text);
changeDrawableColor(TootActivity.this, R.drawable.ic_check,R.color.dark_text);
}else {
changeDrawableColor(TootActivity.this, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_action_camera,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_previous,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_skip_next,R.color.black);
changeDrawableColor(TootActivity.this, R.drawable.ic_check,R.color.black);
}
}
}

View File

@ -17,6 +17,7 @@ public class StoredStatus {
private int jobId;
private boolean isSent;
private Status status;
private Status statusReply;
private String instance;
private String userId;
@ -92,4 +93,12 @@ public class StoredStatus {
public void setUserId(String userId) {
this.userId = userId;
}
public Status getStatusReply() {
return statusReply;
}
public void setStatusReply(Status statusReply) {
this.statusReply = statusReply;
}
}

View File

@ -14,31 +14,36 @@ package fr.gouv.etalab.mastodon.fragments;
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import com.evernote.android.job.JobManager;
import com.evernote.android.job.JobRequest;
import android.widget.TextView;
import java.util.List;
import java.util.Set;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveScheduledTootsAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
import fr.gouv.etalab.mastodon.drawers.ScheduledTootsListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveScheduledTootsInterface;
import fr.gouv.etalab.mastodon.jobs.ScheduledTootsSyncJob;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO;
import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
/**
@ -52,6 +57,7 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev
private AsyncTask<Void, Void, Void> asyncTask;
private RelativeLayout mainLoader, textviewNoAction;
private ListView lv_scheduled_toots;
private TextView warning_battery_message;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -62,6 +68,7 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev
lv_scheduled_toots = (ListView) rootView.findViewById(R.id.lv_scheduled_toots);
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
warning_battery_message = (TextView) rootView.findViewById(R.id.warning_battery_message);
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
@ -77,6 +84,61 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev
super.onResume();
//Retrieves scheduled toots
asyncTask = new RetrieveScheduledTootsAsyncTask(context, DisplayScheduledTootsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//Battery saver is one and user never asked to stop showing the message
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK) {
changeDrawableColor(context, R.drawable.ic_action_warning, R.color.colorAccentD);
changeDrawableColor(context, R.drawable.ic_cancel, R.color.colorAccentD);
}else {
changeDrawableColor(context, R.drawable.ic_action_warning, R.color.colorAccent);
changeDrawableColor(context, R.drawable.ic_cancel, R.color.colorAccent);
}
if( powerManager.isPowerSaveMode() && sharedpreferences.getBoolean(Helper.SHOW_BATTERY_SAVER_MESSAGE,true)){
warning_battery_message.setVisibility(View.VISIBLE);
}else {
warning_battery_message.setVisibility(View.GONE);
}
warning_battery_message.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() >= (warning_battery_message.getRight() - warning_battery_message.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOW_BATTERY_SAVER_MESSAGE, false);
editor.apply();
warning_battery_message.setVisibility(View.GONE);
return true;
}
}
return false;
}
});
warning_battery_message.setOnClickListener(new View.OnClickListener() {
@SuppressLint("BatteryLife")
@Override
public void onClick(View v) {
try {
Intent battSaverIntent = new Intent();
battSaverIntent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$BatterySaverSettingsActivity"));
startActivityForResult(battSaverIntent, 0);
}catch (ActivityNotFoundException e){
try {
Intent batterySaverIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
batterySaverIntent = new Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS);
startActivity(batterySaverIntent);
}
}catch (ActivityNotFoundException ignored){}
}
}
});
}else {
warning_battery_message.setVisibility(View.GONE);
}
}
@Override
@ -99,7 +161,6 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev
}
@Override
public void onRetrieveScheduledToots(List<StoredStatus> storedStatuses) {

View File

@ -156,6 +156,7 @@ public class Helper {
public static final String SCOPE = "scope";
public static final String SCOPES = "scopes";
public static final String WEBSITE = "website";
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 CLIP_BOARD = "clipboard";

View File

@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper;
@SuppressWarnings("WeakerAccess")
public class Sqlite extends SQLiteOpenHelper {
public static final int DB_VERSION = 2;
public static final int DB_VERSION = 3;
public static final String DB_NAME = "mastodon_etalab_db";
public static SQLiteDatabase db;
private static Sqlite sInstance;
@ -72,6 +72,7 @@ public class Sqlite extends SQLiteOpenHelper {
public static final String COL_ID = "ID";
public static final String COL_STATUS_SERIALIZED = "STATUS_SERIALIZED";
public static final String COL_STATUS_REPLY_SERIALIZED = "STATUS_REPLY_SERIALIZED";
public static final String COL_DATE_CREATION = "DATE_CREATION";
public static final String COL_IS_SCHEDULED = "IS_SCHEDULED";
public static final String COL_DATE_SCHEDULED = "DATE_SCHEDULED";
@ -110,6 +111,8 @@ public class Sqlite extends SQLiteOpenHelper {
switch (oldVersion) {
case 1:
db.execSQL(CREATE_TABLE_STATUSES_STORED);
case 2:
db.execSQL("ALTER TABLE " + TABLE_STATUSES_STORED + " ADD COLUMN " + COL_STATUS_REPLY_SERIALIZED + " TEXT");
default:
break;
}

View File

@ -51,8 +51,7 @@ public class StatusStoredDAO {
* @param status Status
* @return boolean
*/
public long insertStatus(Status status)
{
public long insertStatus(Status status, Status statusReply) {
ContentValues values = new ContentValues();
String serializedStatus = Helper.statusToStringStorage(status);
@ -61,6 +60,10 @@ public class StatusStoredDAO {
String instance = Helper.getLiveInstance(context);
if( userId == null || instance == null)
return -1;
if( statusReply != null){
String serializedStatusReply = Helper.statusToStringStorage(statusReply);
values.put(Sqlite.COL_STATUS_REPLY_SERIALIZED, serializedStatusReply);
}
values.put(Sqlite.COL_STATUS_SERIALIZED, serializedStatus);
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(context, new Date()));
values.put(Sqlite.COL_IS_SCHEDULED, 0);
@ -300,6 +303,8 @@ public class StatusStoredDAO {
storedStatus.setId(c.getInt(c.getColumnIndex(Sqlite.COL_ID)));
Status status = Helper.restoreStatusFromString(c.getString(c.getColumnIndex(Sqlite.COL_STATUS_SERIALIZED)));
storedStatus.setStatus(status);
Status statusReply = Helper.restoreStatusFromString(c.getString(c.getColumnIndex(Sqlite.COL_STATUS_REPLY_SERIALIZED)));
storedStatus.setStatusReply(statusReply);
storedStatus.setSent(c.getInt(c.getColumnIndex(Sqlite.COL_SENT)) == 1);
storedStatus.setJobId(c.getInt(c.getColumnIndex(Sqlite.COL_IS_SCHEDULED)));
storedStatus.setCreation_date(Helper.stringToDate(context, c.getString(c.getColumnIndex(Sqlite.COL_DATE_CREATION))));
@ -329,6 +334,8 @@ public class StatusStoredDAO {
storedStatus.setId(c.getInt(c.getColumnIndex(Sqlite.COL_ID)));
Status status = Helper.restoreStatusFromString(c.getString(c.getColumnIndex(Sqlite.COL_STATUS_SERIALIZED)));
storedStatus.setStatus(status);
Status statusReply = Helper.restoreStatusFromString(c.getString(c.getColumnIndex(Sqlite.COL_STATUS_REPLY_SERIALIZED)));
storedStatus.setStatusReply(statusReply);
storedStatus.setSent(c.getInt(c.getColumnIndex(Sqlite.COL_SENT)) == 1);
storedStatus.setJobId(c.getInt(c.getColumnIndex(Sqlite.COL_IS_SCHEDULED)) );
storedStatus.setCreation_date(Helper.stringToDate(context, c.getString(c.getColumnIndex(Sqlite.COL_DATE_CREATION))));

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -31,6 +31,29 @@
android:divider="@null"
>
</ListView>
<TextView
android:id="@+id/warning_battery_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_warning"
android:drawableStart="@drawable/ic_action_warning"
android:drawableRight="@drawable/ic_cancel"
android:drawableEnd="@drawable/ic_cancel"
android:drawablePadding="5dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:clickable="true"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="100dp"
android:layout_marginRight="100dp"
android:textColor="?attr/colorAccent"
android:textStyle="italic"
android:textSize="12sp"
android:text="@string/warning_battery"
android:layout_marginBottom="5dp"
android:layout_alignParentBottom="true"
/>
<RelativeLayout
android:id="@+id/no_action"
android:visibility="gone"

View File

@ -190,6 +190,7 @@
<string name="media_count">Média(s): %d</string>
<string name="toot_scheduled">Le pouet a été programmé !</string>
<string name="toot_scheduled_date">La date doit être supérieure à l\'heure actuelle !</string>
<string name="warning_battery">L\'économiseur de batterie est activé ! Il se peut que cela ne fonctionne pas comme prévu.</string>
<!-- Notifications -->
<string name="no_notifications">Aucune notification à afficher</string>

View File

@ -196,7 +196,7 @@
<string name="media_count">Media: %d</string>
<string name="toot_scheduled">The toot has been scheduled!</string>
<string name="toot_scheduled_date">The scheduled date must be greater than the current hour!</string>
<string name="warning_battery">Battery saver is enabled! It might not work as expected.</string>
<!-- Notifications -->
<string name="no_notifications">No notification to display</string>
<string name="notif_mention">mentioned your status</string>