add option: set maximum retry times of uploading image

This commit is contained in:
Len Chan 2019-07-04 00:41:26 +08:00
parent a1a775a2df
commit 8adc3438f9
5 changed files with 50 additions and 1 deletions

View File

@ -2544,6 +2544,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String scheme = sharedpreferences.getString(Helper.SET_ONION_SCHEME+Helper.getLiveInstance(context), "https");
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
String url = null;
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
url = scheme + "://" + Helper.getLiveInstance(context) + "/api/v1/media";
@ -2563,7 +2564,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
}else {
request.addFileToUpload(uri.toString().replace("file://",""), "media");
};
request.addParameter("filename", fileName).setMaxRetries(1)
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes)
.startUpload();
} catch (MalformedURLException e) {
e.printStackTrace();

View File

@ -600,6 +600,22 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
}
});
int upload_img_max_retry_times = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
final SeekBar max_times_bar = rootView.findViewById(R.id.max_upload_image_retry_times);
final TextView max_times_value = rootView.findViewById(R.id.max_upload_image_retry_times_value);
max_times_bar.setProgress(upload_img_max_retry_times);
max_times_value.setText(String.valueOf(upload_img_max_retry_times));
max_times_bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override public void onStartTrackingTouch(SeekBar seekBar) {}
@Override public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
max_times_value.setText(String.valueOf(progress));
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, progress);
editor.apply();
}
});
boolean remember_position_home = sharedpreferences.getBoolean(Helper.SET_REMEMBER_POSITION_HOME, true);
final CheckBox set_remember_position = rootView.findViewById(R.id.set_remember_position);
set_remember_position.setChecked(remember_position_home);

View File

@ -402,6 +402,7 @@ public class Helper {
public static final String SET_EXPAND_CW = "set_expand_cw";
public static final String SET_EXPAND_MEDIA = "set_expand_media";
public static final String SET_PHOTO_EDITOR = "set_photo_editor";
public static final String MAX_UPLOAD_IMG_RETRY_TIMES = "max_upload_img_retry_times";
public static final String SET_DISPLAY_FOLLOW_INSTANCE = "set_display_follow_instance";
public static final String SET_DISPLAY_NEW_BADGE = "set_display_new_badge";
public static final String SET_DISPLAY_BOT_ICON = "set_display_bot_icon";

View File

@ -1552,6 +1552,36 @@
android:text="@string/set_photo_editor"
android:layout_height="wrap_content" />
<!-- maximum upload image retry times -->
<TextView
android:textSize="16sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/upload_image_maximum_retry_times"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/max_upload_image_retry_times_value"
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="wrap_content" />
<SeekBar
android:layout_gravity="center_vertical"
android:id="@+id/max_upload_image_retry_times"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="10">
</SeekBar>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -1099,6 +1099,7 @@
<string name="u_interface">Interface</string>
<string name="battery">Battery</string>
<string name="compose">Compose</string>
<string name="upload_image_maximum_retry_times">Upload image maximum retry times</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>