mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add delete task
This commit is contained in:
parent
4b0f1f6a09
commit
369570537e
23 changed files with 398 additions and 146 deletions
|
|
@ -4,6 +4,12 @@ Fixes #{GitHub issue number}
|
|||
|
||||
{Describe the changes made and why they were made.}
|
||||
|
||||
## Tests performed
|
||||
|
||||
Tested on {API level & name of device/emulator}, with {build variant, e.g. ProdDebug}.
|
||||
|
||||
{Please test your PR at least once before submitting.}
|
||||
|
||||
## Screenshots showing what changed
|
||||
|
||||
{Only for user interface changes, otherwise remove this section. See [how to take a screenshot](https://android.stackexchange.com/questions/1759/how-to-take-a-screenshot-with-an-android-device)}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,11 @@ dependencies {
|
|||
compile 'com.facebook.fresco:fresco:1.3.0'
|
||||
compile 'com.facebook.stetho:stetho:1.5.0'
|
||||
|
||||
compile 'com.android.support:multidex:1.0.3'
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.robolectric:robolectric:3.7.1'
|
||||
testCompile "org.robolectric:multidex:3.4.2"
|
||||
|
||||
testCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||
|
|
@ -94,6 +97,8 @@ dependencies {
|
|||
implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION"
|
||||
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||
kapt "com.google.dagger:dagger-android-processor:$DAGGER_VERSION"
|
||||
|
||||
compile 'com.borjabravo:readmoretextview:2.1.0'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
|||
|
|
@ -91,10 +91,6 @@
|
|||
android:name=".notification.NotificationActivity"
|
||||
android:label="@string/navigation_item_notification" />
|
||||
|
||||
<activity
|
||||
android:name=".delete.DeleteActivity"
|
||||
android:label="@string/title_activity_delete" />
|
||||
|
||||
<service android:name=".upload.UploadService" />
|
||||
|
||||
<service
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
@ -14,6 +17,8 @@ import butterknife.OnClick;
|
|||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||
import fr.free.nrw.commons.ui.widget.HtmlTextView;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
|
||||
/**
|
||||
* Represents about screen of this app
|
||||
*/
|
||||
|
|
@ -27,12 +32,12 @@ public class AboutActivity extends NavigationBaseActivity {
|
|||
* @param savedInstanceState Data bundle
|
||||
*/
|
||||
@Override
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
String aboutText = getString(R.string.about_license);
|
||||
aboutLicenseText.setHtmlText(aboutText);
|
||||
|
||||
|
|
@ -42,35 +47,70 @@ public class AboutActivity extends NavigationBaseActivity {
|
|||
|
||||
@OnClick(R.id.facebook_launch_icon)
|
||||
public void launchFacebook(View view) {
|
||||
|
||||
Intent intent;
|
||||
try {
|
||||
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + "1921335171459985"));
|
||||
intent.setPackage("com.facebook.katana");
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + "1921335171459985\\"));
|
||||
if(intent.resolveActivity(this.getPackageManager()) != null){
|
||||
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.github_launch_icon)
|
||||
public void launchGithub(View view) {
|
||||
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
|
||||
//check if web browser available
|
||||
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
|
||||
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.website_launch_icon)
|
||||
public void launchWebsite(View view) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://commons-app.github.io/\\"));
|
||||
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
|
||||
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.about_rate_us)
|
||||
public void launchRatings(View view){
|
||||
Utils.rateApp(this);
|
||||
}
|
||||
|
||||
@OnClick(R.id.about_credits)
|
||||
public void launchCredits(View view) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
|
||||
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
|
||||
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.about_privacy_policy)
|
||||
public void launchPrivacyPolicy(View view) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
|
||||
if (browserIntent.resolveActivity(this.getPackageManager()) != null) {
|
||||
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.stetho.Stetho;
|
||||
|
|
@ -40,7 +41,7 @@ import timber.log.Timber;
|
|||
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt,
|
||||
resDialogOkToast = R.string.crash_dialog_ok_toast
|
||||
)
|
||||
public class CommonsApplication extends Application {
|
||||
public class CommonsApplication extends MultiDexApplication {
|
||||
|
||||
@Inject SessionManager sessionManager;
|
||||
@Inject DBOpenHelper dbOpenHelper;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public class Media implements Parcelable {
|
|||
protected String license;
|
||||
protected String creator;
|
||||
protected ArrayList<String> categories; // as loaded at runtime?
|
||||
protected boolean requestedDeletion;
|
||||
private Map<String, String> descriptions; // multilingual descriptions as loaded
|
||||
private HashMap<String, Object> tags = new HashMap<>();
|
||||
private @Nullable LatLng coordinates;
|
||||
|
|
@ -53,6 +54,7 @@ public class Media implements Parcelable {
|
|||
protected Media() {
|
||||
this.categories = new ArrayList<>();
|
||||
this.descriptions = new HashMap<>();
|
||||
this.requestedDeletion = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -416,4 +418,12 @@ public class Media implements Parcelable {
|
|||
parcel.writeStringList(categories);
|
||||
parcel.writeMap(descriptions);
|
||||
}
|
||||
|
||||
public void setRequestedDeletion(){
|
||||
requestedDeletion = true;
|
||||
}
|
||||
|
||||
public boolean getRequestedDeletion(){
|
||||
return requestedDeletion;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,14 +166,13 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static void rateApp(Context context) {
|
||||
final String appPackageName = context.getPackageName();
|
||||
final String appPackageName = BuildConfig.class.getPackage().getName();
|
||||
try {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
|
||||
}
|
||||
catch (android.content.ActivityNotFoundException anfe) {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
public static void handleWebUrl(Context context,Uri url){
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
package fr.free.nrw.commons.delete;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class DeleteActivity extends AppCompatActivity {
|
||||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ApplicationlessInjection
|
||||
.getInstance(this.getApplicationContext())
|
||||
.getCommonsApplicationComponent()
|
||||
.inject(this);
|
||||
|
||||
setContentView(R.layout.activity_delete);
|
||||
|
||||
String authCookie = sessionManager.getAuthCookie();
|
||||
Timber.d(authCookie);
|
||||
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
String editToken = "noooooooo";
|
||||
|
||||
try {
|
||||
editToken = mwApi.getEditToken();
|
||||
} catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
}
|
||||
Timber.d(editToken);
|
||||
|
||||
}
|
||||
}
|
||||
130
app/src/main/java/fr/free/nrw/commons/delete/DeleteTask.java
Normal file
130
app/src/main/java/fr/free/nrw/commons/delete/DeleteTask.java
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
package fr.free.nrw.commons.delete;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
|
||||
public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
||||
private Context context;
|
||||
private Media media;
|
||||
private String reason;
|
||||
|
||||
public DeleteTask (Context context, Media media, String reason){
|
||||
this.context = context;
|
||||
this.media = media;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute(){
|
||||
ApplicationlessInjection
|
||||
.getInstance(context.getApplicationContext())
|
||||
.getCommonsApplicationComponent()
|
||||
.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void ...voids) {
|
||||
String editToken;
|
||||
String authCookie;
|
||||
String summary = "Nominating " + media.getFilename() +" for deletion.";
|
||||
|
||||
authCookie = sessionManager.getAuthCookie();
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
|
||||
try {
|
||||
editToken = mwApi.getEditToken();
|
||||
}
|
||||
catch (Exception e){
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
if (editToken.equals("+\\")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
String fileDeleteString = "{{delete|reason=" + reason +
|
||||
"|subpage=" +media.getFilename() +
|
||||
"|day=" + calendar.get(Calendar.DAY_OF_MONTH) +
|
||||
"|month=" + calendar.getDisplayName(Calendar.MONTH,Calendar.LONG, Locale.getDefault()) +
|
||||
"|year=" + calendar.get(Calendar.YEAR) +
|
||||
"}}";
|
||||
try{
|
||||
mwApi.prependEdit(editToken,fileDeleteString+"\n",
|
||||
media.getFilename(),summary);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
String subpageString = "=== [[:" + media.getFilename() + "]] ===\n" +
|
||||
reason +
|
||||
" ~~~~";
|
||||
try{
|
||||
mwApi.edit(editToken,subpageString+"\n",
|
||||
"Commons:Deletion requests/"+media.getFilename(),summary);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
String logPageString = "\n{{Commons:Deletion requests/" + media.getFilename() +
|
||||
"}}\n";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
||||
String date = sdf.format(calendar.getTime());
|
||||
try{
|
||||
mwApi.appendEdit(editToken,logPageString+"\n",
|
||||
"Commons:Deletion requests/"+date,summary);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
||||
"}} ~~~~";
|
||||
try{
|
||||
mwApi.appendEdit(editToken,userPageString+"\n",
|
||||
"User_Talk:"+sessionManager.getCurrentAccount().name,summary);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
String toastText = "";
|
||||
if (result) {
|
||||
toastText = "Successfully requested deletion.";
|
||||
}
|
||||
else{
|
||||
toastText = "Could not request deletion.";
|
||||
}
|
||||
Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,8 +9,10 @@ import dagger.android.support.AndroidSupportInjectionModule;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.contributions.ContributionsSyncAdapter;
|
||||
import fr.free.nrw.commons.delete.DeleteActivity;
|
||||
import fr.free.nrw.commons.delete.DeleteTask;
|
||||
import fr.free.nrw.commons.modifications.ModificationsSyncAdapter;
|
||||
import fr.free.nrw.commons.settings.SettingsFragment;
|
||||
|
||||
|
|
@ -35,7 +37,7 @@ public interface CommonsApplicationComponent extends AndroidInjector<Application
|
|||
|
||||
void inject(LoginActivity activity);
|
||||
|
||||
void inject(DeleteActivity activity);
|
||||
void inject(DeleteTask deleteTask);
|
||||
|
||||
void inject(SettingsFragment fragment);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,22 @@
|
|||
package fr.free.nrw.commons.media;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.DataSetObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -34,13 +38,14 @@ import fr.free.nrw.commons.MediaDataExtractor;
|
|||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.PageTitle;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.delete.DeleteActivity;
|
||||
import fr.free.nrw.commons.delete.DeleteTask;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.ui.widget.CompatTextView;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
|
||||
public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
private boolean editable;
|
||||
|
|
@ -187,12 +192,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
Timber.d("MediaDetailFragment ready to display details");
|
||||
displayMediaDetails(media);
|
||||
}
|
||||
if (media instanceof Contribution) {
|
||||
Contribution c = (Contribution) media;
|
||||
if (c.getState()!= Contribution.STATE_COMPLETED) {
|
||||
delete.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayMediaDetails(final Media media) {
|
||||
|
|
@ -283,6 +282,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
categoryNames.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
rebuildCatList();
|
||||
|
||||
delete.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setOnClickListeners(final Media media) {
|
||||
|
|
@ -295,13 +296,60 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
if (media.getCoordinates() != null) {
|
||||
coordinates.setOnClickListener(v -> openMap(media.getCoordinates()));
|
||||
}
|
||||
if (delete.getVisibility()!=View.GONE){
|
||||
if (delete.getVisibility()==View.VISIBLE){
|
||||
delete.setOnClickListener(v -> {
|
||||
Timber.d("clicked delete");
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("media",media);
|
||||
Intent deleteIntent = new Intent(getActivity(), DeleteActivity.class);
|
||||
startActivity(deleteIntent);
|
||||
AlertDialog alert;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage("Sure you want to delete?");
|
||||
builder.setCancelable(true);
|
||||
builder.setPositiveButton(
|
||||
R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setTitle("Why should this file be deleted?");
|
||||
final EditText input = new EditText(getActivity());
|
||||
alert.setView(input);
|
||||
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
String reason = input.getText().toString();
|
||||
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
|
||||
deleteTask.execute();
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {}
|
||||
});
|
||||
AlertDialog d = alert.create();
|
||||
input.addTextChangedListener(new TextWatcher() {
|
||||
private void handleText() {
|
||||
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
if(input.getText().length() == 0) {
|
||||
okButton.setEnabled(false);
|
||||
} else {
|
||||
okButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterTextChanged(Editable arg0) {
|
||||
handleText();
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
});
|
||||
d.show();
|
||||
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(
|
||||
R.string.no,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {}
|
||||
});
|
||||
alert = builder.create();
|
||||
alert.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -326,7 +374,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
Intent viewIntent = new Intent();
|
||||
viewIntent.setAction(Intent.ACTION_VIEW);
|
||||
viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri());
|
||||
//check if web browser available
|
||||
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
|
||||
startActivity(viewIntent);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
return item;
|
||||
|
|
@ -406,7 +460,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
private void openWebBrowser(String url) {
|
||||
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
//check if web browser available
|
||||
if (browser.resolveActivity(getActivity().getPackageManager()) != null) {
|
||||
startActivity(browser);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void openMap(LatLng coordinates) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
|
@ -40,6 +41,7 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
|||
import static android.content.Context.DOWNLOAD_SERVICE;
|
||||
import static android.content.Intent.ACTION_VIEW;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
|
||||
public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {
|
||||
|
||||
|
|
@ -118,7 +120,14 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
Intent viewIntent = new Intent();
|
||||
viewIntent.setAction(ACTION_VIEW);
|
||||
viewIntent.setData(m.getFilePageTitle().getMobileUri());
|
||||
//check if web browser available
|
||||
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
|
||||
startActivity(viewIntent);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
return true;
|
||||
case R.id.menu_download_current_image:
|
||||
// Download
|
||||
|
|
|
|||
|
|
@ -205,6 +205,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
.getNodes("/api/query/pages/page/imageinfo").size() > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String edit(String editToken, String processedPageContent, String filename, String summary) throws IOException {
|
||||
|
|
@ -217,6 +218,31 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
.getString("/api/edit/@result");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String appendEdit(String editToken, String processedPageContent, String filename, String summary) throws IOException {
|
||||
return api.action("edit")
|
||||
.param("title", filename)
|
||||
.param("token", editToken)
|
||||
.param("appendtext", processedPageContent)
|
||||
.param("summary", summary)
|
||||
.post()
|
||||
.getString("/api/edit/@result");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String prependEdit(String editToken, String processedPageContent, String filename, String summary) throws IOException {
|
||||
return api.action("edit")
|
||||
.param("title", filename)
|
||||
.param("token", editToken)
|
||||
.param("prependtext", processedPageContent)
|
||||
.param("summary", summary)
|
||||
.post()
|
||||
.getString("/api/edit/@result");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findThumbnailByFilename(String filename) throws IOException {
|
||||
return api.action("query")
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ public interface MediaWikiApi {
|
|||
@Nullable
|
||||
String edit(String editToken, String processedPageContent, String filename, String summary) throws IOException;
|
||||
|
||||
@Nullable
|
||||
String prependEdit(String editToken, String processedPageContent, String filename, String summary) throws IOException;
|
||||
|
||||
@Nullable
|
||||
String appendEdit(String editToken, String processedPageContent, String filename, String summary) throws IOException;
|
||||
|
||||
@NonNull
|
||||
MediaResult fetchMediaByFilename(String filename) throws IOException;
|
||||
|
||||
|
|
@ -58,8 +64,6 @@ public interface MediaWikiApi {
|
|||
|
||||
boolean existingFile(String fileSha1) throws IOException;
|
||||
|
||||
|
||||
|
||||
@NonNull
|
||||
LogEventResult logEvents(String user, String lastModified, String queryContinue, int limit) throws IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.pedrogomez.renderers.RVRendererAdapter;
|
||||
|
||||
|
|
@ -25,6 +26,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
|
||||
/**
|
||||
* Created by root on 18.12.2017.
|
||||
*/
|
||||
|
|
@ -71,7 +74,14 @@ public class NotificationActivity extends NavigationBaseActivity {
|
|||
if (url == null || url.equals("")) {
|
||||
return;
|
||||
}
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
//check if web browser available
|
||||
if(browser.resolveActivity(this.getPackageManager()) != null){
|
||||
startActivity(browser);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void setAdapter(List<Notification> notificationList) {
|
||||
|
|
@ -85,6 +95,7 @@ public class NotificationActivity extends NavigationBaseActivity {
|
|||
|
||||
public static void startYourself(Context context) {
|
||||
Intent intent = new Intent(context, NotificationActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package fr.free.nrw.commons.notification;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.borjabravo.readmoretextview.ReadMoreTextView;
|
||||
import com.pedrogomez.renderers.Renderer;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
|
@ -17,8 +19,8 @@ import fr.free.nrw.commons.R;
|
|||
*/
|
||||
|
||||
public class NotificationRenderer extends Renderer<Notification> {
|
||||
@BindView(R.id.title) TextView title;
|
||||
@BindView(R.id.description) TextView description;
|
||||
@BindView(R.id.title) ReadMoreTextView title;
|
||||
@BindView(R.id.description) ReadMoreTextView description;
|
||||
@BindView(R.id.time) TextView time;
|
||||
@BindView(R.id.icon) ImageView icon;
|
||||
private NotificationClicked listener;
|
||||
|
|
@ -46,9 +48,13 @@ public class NotificationRenderer extends Renderer<Notification> {
|
|||
@Override
|
||||
public void render() {
|
||||
Notification notification = getContent();
|
||||
title.setText(notification.notificationText);
|
||||
StringBuilder str = new StringBuilder(notification.notificationText);
|
||||
str.append(" " );
|
||||
title.setText(str);
|
||||
time.setText(notification.date);
|
||||
description.setText(notification.description);
|
||||
StringBuilder desc = new StringBuilder(notification.description);
|
||||
desc.append(" ");
|
||||
description.setText(desc);
|
||||
switch (notification.notificationType) {
|
||||
case THANK_YOU_EDIT:
|
||||
icon.setImageResource(R.drawable.ic_edit_black_24dp);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -65,9 +66,6 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
|
|||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.activity_share, menu);
|
||||
if (titleEdit != null) {
|
||||
menu.findItem(R.id.menu_upload_single).setEnabled(titleEdit.getText().length() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -76,6 +74,11 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
|
|||
//What happens when the 'submit' icon is tapped
|
||||
case R.id.menu_upload_single:
|
||||
|
||||
if (titleEdit.getText().toString().isEmpty()) {
|
||||
Toast.makeText(getContext(), R.string.add_title_toast, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
String title = titleEdit.getText().toString();
|
||||
String desc = descEdit.getText().toString();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include
|
||||
android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
|
@ -251,19 +251,15 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/small_gap" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/standard_gap">
|
||||
<Button
|
||||
android:id="@+id/nominateDeletion"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:textColor="@color/deleteTextColor"
|
||||
android:layout_margin="@dimen/standard_gap"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nominate_deletion"/>
|
||||
</LinearLayout>
|
||||
android:text="@string/nominate_deletion"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:foreground="?selectableItemBackground"
|
||||
android:minHeight="72dp"
|
||||
>
|
||||
android:minHeight="72dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
|
|
@ -34,7 +33,7 @@
|
|||
tools:text="@string/placeholder_place_distance"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
<com.borjabravo.readmoretextview.ReadMoreTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -46,12 +45,13 @@
|
|||
android:layout_toRightOf="@id/icon"
|
||||
android:layout_toStartOf="@id/time"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
app:trimLines="2"
|
||||
app:colorClickableText="#969494"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
tools:text="@string/placeholder_place_name"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
<com.borjabravo.readmoretextview.ReadMoreTextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -62,7 +62,8 @@
|
|||
android:layout_below="@id/title"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="4"
|
||||
app:trimLines="2"
|
||||
app:colorClickableText="#969494"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
tools:text="@string/placeholder_place_description"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
<item android:id="@+id/menu_upload_single"
|
||||
android:title="@string/menu_upload_single"
|
||||
android:icon="@drawable/ic_send_white_24dp"
|
||||
android:enabled="false"
|
||||
android:enabled="true"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
<string name="menu_share">Share</string>
|
||||
<string name="menu_open_in_browser">View in Browser</string>
|
||||
<string name="share_title_hint">Title</string>
|
||||
<string name="add_title_toast">Please provide a title for this file</string>
|
||||
<string name="share_description_hint">Description</string>
|
||||
<string name="login_failed_network">Unable to login - network failure</string>
|
||||
<string name="login_failed_username">Unable to login - please check your username</string>
|
||||
|
|
@ -75,7 +76,6 @@
|
|||
<string name="categories_activity_title">Categories</string>
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
<string name="title_activity_signup">Sign Up</string>
|
||||
<string name="title_activity_delete">Request Deletion</string>
|
||||
<string name="menu_about">About</string>
|
||||
<string name="about_license">The Wikimedia Commons app is an open-source app created and maintained by grantees and volunteers of the Wikimedia community. The Wikimedia Foundation is not involved in the creation, development, or maintenance of the app. </string>
|
||||
<string name="trademarked_name" translatable="false">Wikimedia Commons</string>
|
||||
|
|
@ -225,6 +225,7 @@
|
|||
<string name="login_to_your_account">Login to your account</string>
|
||||
<string name="send_log_file">Send log file</string>
|
||||
<string name="send_log_file_description">Send log file to developers via email</string>
|
||||
<string name="no_web_browser">No web browser found to open URL</string>
|
||||
<string name="null_url">Error! URL not found</string>
|
||||
<string name="nominate_deletion">Nominate for Deletion</string>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,29 @@
|
|||
gradleVersion = 3.0.0
|
||||
|
||||
SUPPORT_LIB_VERSION = 26.0.2
|
||||
|
||||
## Project-wide Gradle settings.
|
||||
#
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
#
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
#
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
#Thu Mar 01 15:28:48 IST 2018
|
||||
systemProp.http.proxyPort=0
|
||||
compileSdkVersion=android-26
|
||||
buildToolsVersion = 26.0.2
|
||||
|
||||
minSdkVersion = 15
|
||||
|
||||
targetSdkVersion = 25
|
||||
android.useDeprecatedNdk=true
|
||||
|
||||
# Library dependencies
|
||||
BUTTERKNIFE_VERSION=8.6.0
|
||||
DAGGER_VERSION=2.13
|
||||
LEAK_CANARY=1.5.4
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
||||
#TODO: Temporary disabled. https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#aapt2
|
||||
#Refer to PR: https://github.com/commons-app/apps-android-commons/pull/932
|
||||
buildToolsVersion=26.0.2
|
||||
targetSdkVersion=25
|
||||
android.enableAapt2=false
|
||||
SUPPORT_LIB_VERSION=26.0.2
|
||||
minSdkVersion=15
|
||||
systemProp.http.proxyHost=
|
||||
LEAK_CANARY=1.5.4
|
||||
DAGGER_VERSION=2.13
|
||||
gradleVersion=3.0.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue