Skip to content

Commit de9bb89

Browse files
author
Suchit Kar
committed
Merge branch 'master' of https://github.com/commons-app/apps-android-commons into rtl-upload
2 parents c3faf25 + f869520 commit de9bb89

38 files changed

+1044
-270
lines changed

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ dependencies {
1818
implementation 'com.google.code.gson:gson:2.8.1'
1919
implementation 'com.jakewharton.timber:timber:4.5.1'
2020
implementation 'info.debatty:java-string-similarity:0.24'
21-
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.2.1@aar'){
21+
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.4.1@aar'){
2222
transitive=true
2323
}
2424

2525

2626
implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION"
2727
implementation "com.android.support:appcompat-v7:$SUPPORT_LIB_VERSION"
2828
implementation "com.android.support:design:$SUPPORT_LIB_VERSION"
29+
implementation "com.android.support:customtabs:$SUPPORT_LIB_VERSION"
2930

3031
implementation "com.android.support:cardview-v7:$SUPPORT_LIB_VERSION"
3132

@@ -48,7 +49,7 @@ dependencies {
4849
compile 'com.facebook.stetho:stetho:1.5.0'
4950

5051
testCompile 'junit:junit:4.12'
51-
testCompile 'org.robolectric:robolectric:3.4'
52+
testCompile 'org.robolectric:robolectric:3.7.1'
5253

5354
testCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
5455
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
@@ -77,7 +78,7 @@ dependencies {
7778
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
7879

7980
testImplementation 'junit:junit:4.12'
80-
testImplementation 'org.robolectric:robolectric:3.4'
81+
testImplementation 'org.robolectric:robolectric:3.7.1'
8182
testImplementation 'org.mockito:mockito-all:1.10.19'
8283

8384
testImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'

app/src/main/java/fr/free/nrw/commons/AboutActivity.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Bundle;
6+
import android.support.customtabs.CustomTabsIntent;
7+
import android.support.v4.content.ContextCompat;
68
import android.view.View;
79
import android.widget.TextView;
810

@@ -47,22 +49,29 @@ public void launchFacebook(View view) {
4749
intent.setPackage("com.facebook.katana");
4850
startActivity(intent);
4951
} catch (Exception e) {
50-
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + "1921335171459985")));
52+
Utils.handleWebUrl(this,Uri.parse("https://www.facebook.com/" + "1921335171459985"));
5153
}
52-
5354
}
5455

5556
@OnClick(R.id.github_launch_icon)
5657
public void launchGithub(View view) {
57-
58-
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/commons-app/apps-android-commons\\"));
59-
startActivity(browserIntent);
58+
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
6059
}
6160

6261
@OnClick(R.id.website_launch_icon)
6362
public void launchWebsite(View view) {
63+
Utils.handleWebUrl(this,Uri.parse("https://commons-app.github.io/\\"));
64+
}
6465

65-
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://commons-app.github.io/\\"));
66-
startActivity(browserIntent);
66+
@OnClick(R.id.about_credits)
67+
public void launchCredits(View view) {
68+
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/blob/master/CREDITS/\\"));
6769
}
70+
71+
@OnClick(R.id.about_privacy_policy)
72+
public void launchPrivacyPolicy(View view) {
73+
Utils.handleWebUrl(this,Uri.parse("https://github.com/commons-app/apps-android-commons/wiki/Privacy-policy\\"));
74+
}
75+
76+
6877
}

app/src/main/java/fr/free/nrw/commons/Utils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package fr.free.nrw.commons;
22

33
import android.content.Context;
4+
import android.content.Intent;
5+
import android.net.Uri;
46
import android.preference.PreferenceManager;
57
import android.support.annotation.NonNull;
8+
import android.support.customtabs.CustomTabsIntent;
9+
import android.support.v4.content.ContextCompat;
610

711
import org.apache.commons.codec.binary.Hex;
812
import org.apache.commons.codec.digest.DigestUtils;
@@ -11,6 +15,7 @@
1115
import java.io.IOException;
1216
import java.io.InputStreamReader;
1317
import java.io.UnsupportedEncodingException;
18+
import java.net.URL;
1419
import java.net.URLEncoder;
1520
import java.util.Locale;
1621
import java.util.regex.Matcher;
@@ -159,4 +164,15 @@ public static String getAppLogs() {
159164

160165
return stringBuilder.toString();
161166
}
167+
168+
public static void handleWebUrl(Context context,Uri url){
169+
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
170+
builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor));
171+
builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
172+
builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
173+
CustomTabsIntent customTabsIntent = builder.build();
174+
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
175+
customTabsIntent.launchUrl(context, url);
176+
}
177+
162178
}

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.accounts.AccountAuthenticatorActivity;
55
import android.accounts.AccountAuthenticatorResponse;
66
import android.accounts.AccountManager;
7+
import android.app.Activity;
78
import android.app.ProgressDialog;
89
import android.content.Intent;
910
import android.content.SharedPreferences;
@@ -17,10 +18,12 @@
1718
import android.support.v7.app.AppCompatDelegate;
1819
import android.text.Editable;
1920
import android.text.TextWatcher;
21+
import android.util.Log;
2022
import android.view.MenuInflater;
2123
import android.view.MenuItem;
2224
import android.view.View;
2325
import android.view.ViewGroup;
26+
import android.view.inputmethod.InputMethodManager;
2427
import android.widget.Button;
2528
import android.widget.EditText;
2629
import android.widget.TextView;
@@ -69,6 +72,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
6972
@BindView(R.id.loginTwoFactor) EditText twoFactorEdit;
7073
@BindView(R.id.error_message_container) ViewGroup errorMessageContainer;
7174
@BindView(R.id.error_message) TextView errorMessage;
75+
@BindView(R.id.login_credentials) TextView loginCredentials;
7276
@BindView(R.id.two_factor_container)TextInputLayout twoFactorContainer;
7377
ProgressDialog progressDialog;
7478
private AppCompatDelegate delegate;
@@ -91,14 +95,39 @@ public void onCreate(Bundle savedInstanceState) {
9195
ButterKnife.bind(this);
9296

9397
usernameEdit.addTextChangedListener(textWatcher);
98+
usernameEdit.setOnFocusChangeListener((v, hasFocus) -> {
99+
if (!hasFocus) {
100+
hideKeyboard(v);
101+
}
102+
});
103+
94104
passwordEdit.addTextChangedListener(textWatcher);
105+
passwordEdit.setOnFocusChangeListener((v, hasFocus) -> {
106+
if (!hasFocus) {
107+
hideKeyboard(v);
108+
}
109+
});
110+
95111
twoFactorEdit.addTextChangedListener(textWatcher);
96112
passwordEdit.setOnEditorActionListener(newLoginInputActionListener());
97113

98114
loginButton.setOnClickListener(view -> performLogin());
99115
signupButton.setOnClickListener(view -> signUp());
116+
117+
if(BuildConfig.FLAVOR == "beta"){
118+
loginCredentials.setText(getString(R.string.login_credential));
119+
} else {
120+
loginCredentials.setVisibility(View.GONE);
121+
}
100122
}
101123

124+
125+
public void hideKeyboard(View view) {
126+
InputMethodManager inputMethodManager =(InputMethodManager)this.getSystemService(Activity.INPUT_METHOD_SERVICE);
127+
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
128+
}
129+
130+
102131
@Override
103132
protected void onPostCreate(Bundle savedInstanceState) {
104133
super.onPostCreate(savedInstanceState);

app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package fr.free.nrw.commons.category;
22

3+
4+
import android.app.Activity;
35
import android.content.SharedPreferences;
46
import android.os.Bundle;
57
import android.support.v7.app.AlertDialog;
68
import android.support.v7.widget.LinearLayoutManager;
79
import android.support.v7.widget.RecyclerView;
10+
import android.text.Editable;
811
import android.text.TextUtils;
12+
import android.text.TextWatcher;
13+
import android.util.Log;
914
import android.view.LayoutInflater;
1015
import android.view.Menu;
1116
import android.view.MenuInflater;
1217
import android.view.MenuItem;
1318
import android.view.View;
1419
import android.view.ViewGroup;
20+
import android.view.inputmethod.InputMethodManager;
1521
import android.widget.EditText;
1622
import android.widget.ProgressBar;
1723
import android.widget.TextView;
@@ -37,6 +43,7 @@
3743
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
3844
import fr.free.nrw.commons.mwapi.MediaWikiApi;
3945
import fr.free.nrw.commons.upload.MwVolleyApi;
46+
import fr.free.nrw.commons.upload.SingleUploadFragment;
4047
import fr.free.nrw.commons.utils.StringSortingUtils;
4148
import io.reactivex.Observable;
4249
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -72,6 +79,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
7279
private OnCategoriesSaveHandler onCategoriesSaveHandler;
7380
private HashMap<String, ArrayList<String>> categoriesCache;
7481
private List<CategoryItem> selectedCategories = new ArrayList<>();
82+
private TitleTextWatcher textWatcher = new TitleTextWatcher();
7583

7684
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
7785
if (item.isSelected()) {
@@ -102,6 +110,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
102110
categoriesAdapter = adapterFactory.create(items);
103111
categoriesList.setAdapter(categoriesAdapter);
104112

113+
114+
categoriesFilter.addTextChangedListener(textWatcher);
115+
116+
categoriesFilter.setOnFocusChangeListener((v, hasFocus) -> {
117+
if (!hasFocus) {
118+
hideKeyboard(v);
119+
}
120+
});
121+
105122
RxTextView.textChanges(categoriesFilter)
106123
.takeUntil(RxView.detaches(categoriesFilter))
107124
.debounce(500, TimeUnit.MILLISECONDS)
@@ -110,6 +127,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
110127
return rootView;
111128
}
112129

130+
public void hideKeyboard(View view) {
131+
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
132+
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
133+
}
134+
135+
@Override
136+
public void onDestroyView() {
137+
categoriesFilter.removeTextChangedListener(textWatcher);
138+
super.onDestroyView();
139+
}
140+
141+
113142
@Override
114143
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
115144
menu.clear();
@@ -351,4 +380,21 @@ private void showConfirmationDialog() {
351380
.create()
352381
.show();
353382
}
383+
384+
private class TitleTextWatcher implements TextWatcher {
385+
@Override
386+
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
387+
}
388+
389+
@Override
390+
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
391+
}
392+
393+
@Override
394+
public void afterTextChanged(Editable editable) {
395+
if (getActivity() != null) {
396+
getActivity().invalidateOptionsMenu();
397+
}
398+
}
399+
}
354400
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.support.annotation.NonNull;
1111
import android.support.v4.app.Fragment;
1212
import android.support.v4.app.FragmentTransaction;
13+
import android.support.v4.widget.SwipeRefreshLayout;
1314
import android.support.v7.app.AlertDialog;
1415
import android.view.Menu;
1516
import android.view.MenuInflater;
@@ -60,7 +61,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
6061
private NearbyActivityMode viewMode;
6162
private Disposable placesDisposable;
6263
private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed
63-
64+
@BindView(R.id.swipe_container) SwipeRefreshLayout swipeLayout;
6465
@Override
6566
protected void onCreate(Bundle savedInstanceState) {
6667
super.onCreate(savedInstanceState);
@@ -70,6 +71,13 @@ protected void onCreate(Bundle savedInstanceState) {
7071
bundle = new Bundle();
7172
initDrawer();
7273
initViewState();
74+
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
75+
@Override
76+
public void onRefresh() {
77+
lockNearbyView(false);
78+
refreshView(true);
79+
}
80+
});
7381
}
7482

7583
private void initViewState() {
@@ -309,7 +317,7 @@ private void populatePlaces(List<Place> placeList) {
309317
} else {
310318
setListFragment();
311319
}
312-
320+
swipeLayout.setRefreshing(false);
313321
hideProgressBar();
314322
}
315323

app/src/main/java/fr/free/nrw/commons/nearby/NearbyInfoDialog.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Bundle;
6+
import android.support.customtabs.CustomTabsIntent;
67
import android.support.v4.app.FragmentActivity;
8+
import android.support.v4.content.ContextCompat;
79
import android.support.v7.widget.PopupMenu;
810
import android.view.LayoutInflater;
911
import android.view.MenuItem;
@@ -17,6 +19,7 @@
1719
import butterknife.OnClick;
1820
import butterknife.Unbinder;
1921
import fr.free.nrw.commons.R;
22+
import fr.free.nrw.commons.Utils;
2023
import fr.free.nrw.commons.location.LatLng;
2124
import fr.free.nrw.commons.ui.widget.OverlayDialog;
2225
import fr.free.nrw.commons.utils.DialogUtil;
@@ -141,8 +144,7 @@ void onReadArticleClick() {
141144
}
142145

143146
private void openWebView(Uri link) {
144-
Intent browserIntent = new Intent(Intent.ACTION_VIEW, link);
145-
startActivity(browserIntent);
147+
Utils.handleWebUrl(getContext(),link);
146148
}
147149

148150
@OnClick(R.id.emptyLayout)

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import android.content.Intent;
66
import android.net.Uri;
77
import android.os.Bundle;
8+
import android.support.v7.widget.DividerItemDecoration;
89
import android.support.v7.widget.LinearLayoutManager;
910
import android.support.v7.widget.RecyclerView;
1011

1112
import com.pedrogomez.renderers.RVRendererAdapter;
1213

14+
import java.util.Collections;
1315
import java.util.List;
1416

1517
import javax.inject.Inject;
@@ -45,8 +47,9 @@ protected void onCreate(Bundle savedInstanceState) {
4547
}
4648

4749
private void initListView() {
48-
recyclerView = findViewById(R.id.listView);
4950
recyclerView.setLayoutManager(new LinearLayoutManager(this));
51+
DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
52+
recyclerView.addItemDecoration(itemDecor);
5053
addNotifications();
5154
}
5255

@@ -58,6 +61,7 @@ private void addNotifications() {
5861
.subscribeOn(Schedulers.io())
5962
.observeOn(AndroidSchedulers.mainThread())
6063
.subscribe(notificationList -> {
64+
Collections.reverse(notificationList);
6165
Timber.d("Number of notifications is %d", notificationList.size());
6266
setAdapter(notificationList);
6367
}, throwable -> Timber.e(throwable, "Error occurred while loading notifications"));

0 commit comments

Comments
 (0)