Skip to content

Search activity #2092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

buildToolsVersion buildToolsVersion
buildToolsVersion '28.0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.accounts.Account;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -13,6 +14,7 @@
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -26,6 +28,8 @@

import com.dinuscxj.progressbar.CircleProgressBar;

import org.w3c.dom.Text;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -42,6 +46,7 @@
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -85,6 +90,12 @@ public class AchievementsActivity extends NavigationBaseActivity {
RelativeLayout layoutImageUsedByWiki;
@BindView(R.id.layout_statistics)
LinearLayout layoutStatistics;
@BindView(R.id.images_used_by_wiki_text)
TextView imageByWikiText;
@BindView(R.id.images_reverted_text)
TextView imageRevertedText;
@BindView(R.id.images_upload_text_param)
TextView imageUploadedText;
@Inject
SessionManager sessionManager;
@Inject
Expand Down Expand Up @@ -186,23 +197,42 @@ void shareScreen(Bitmap bitmap) {
*/
private void setAchievements() {
if (checkAccount()) {
compositeDisposable.add(mediaWikiApi
.getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
response -> {
if (response != null) {
setUploadCount(Achievements.from(response));
} else {
//Timber.d(String.valueOf(mediaWikiApi.getAchievements(sessionManager.getCurrentAccount().name)));
/*layoutImageReverts.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);*/
try{

compositeDisposable.add(mediaWikiApi
.getAchievements(Objects.requireNonNull(sessionManager.getCurrentAccount()).name)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
response -> {
if (response != null) {
setUploadCount(Achievements.from(response));
} else {
Timber.d("success");
layoutImageReverts.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
levelNumber.setText("You haven't qualified any level yet");
//onError();
}
},
t -> {
Timber.e(t, "Fetching achievements statistics failed");
onError();
}
},
t -> {
Timber.e(t, "Fetching achievements statistics failed");
onError();
}
));
));
}
catch (Exception e){
Timber.d(e+"success");
/*layoutImageReverts.setVisibility(View.INVISIBLE);
imageView.setVisibility(View.INVISIBLE);
levelNumber.setText("You haven't qualified any level yet");*/
}



}
}

Expand Down Expand Up @@ -247,10 +277,38 @@ private void setAchievementsUploadCount(Achievements achievements, int uploadCou
* @param uploadCount
*/
private void setUploadProgress(int uploadCount){
imagesUploadedProgressbar.setProgress
(100*uploadCount/levelInfo.getMaxUploadCount());
imagesUploadedProgressbar.setProgressTextFormatPattern
(uploadCount +"/" + levelInfo.getMaxUploadCount() );
if (uploadCount==0){
setZeroAchievements();
}else {

imagesUploadedProgressbar.setProgress
(100*uploadCount/levelInfo.getMaxUploadCount());
imagesUploadedProgressbar.setProgressTextFormatPattern
(uploadCount +"/" + levelInfo.getMaxUploadCount() );
}

}

private void setZeroAchievements() {
AlertDialog.Builder builder=new AlertDialog.Builder(this)
.setMessage("You haven't made any contributions yet")
.setPositiveButton("Ok", (dialog, which) -> {
//dismiss
});
AlertDialog dialog = builder.create();
dialog.show();
imagesUploadedProgressbar.setVisibility(View.INVISIBLE);
imageRevertsProgressbar.setVisibility(View.INVISIBLE);
imagesUsedByWikiProgessbar.setVisibility(View.INVISIBLE);
//levelNumber.setText("LEVEL 0");
imageView.setVisibility(View.INVISIBLE);
imageByWikiText.setText("No images used");
imageRevertedText.setText("No image reverted");
imageUploadedText.setText("No images Uploaded");
/*BitmapDrawable bitmapImage = BitmapUtils.writeOnDrawable(bitmap, Integer.toString(levelInfo.getLevelNumber()),this);
imageView.setImageDrawable(bitmapImage);*/
imageView.setVisibility(View.INVISIBLE);

}

/**
Expand Down Expand Up @@ -315,6 +373,7 @@ private void hideProgressBar(Achievements achievements) {
layoutStatistics.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
levelNumber.setVisibility(View.VISIBLE);
//levelNumber.setText("You haven't qualified any level yet");
}
}

Expand Down Expand Up @@ -388,10 +447,10 @@ private void launchAlert(String title, String message){
private boolean checkAccount(){
Account currentAccount = sessionManager.getCurrentAccount();
if (currentAccount == null) {
Timber.d("Current account is null");
ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in));
sessionManager.forceLogin(this);
return false;
Timber.d("Current account is null");
ViewUtil.showLongToast(this, getResources().getString(R.string.user_not_logged_in));
sessionManager.forceLogin(this);
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.PageTitle;
import fr.free.nrw.commons.achievements.FeaturedImages;
import fr.free.nrw.commons.achievements.FeedbackResponse;
import fr.free.nrw.commons.auth.AccountUtil;
import fr.free.nrw.commons.category.CategoryImageUtils;
Expand Down Expand Up @@ -988,7 +989,15 @@ public Single<FeedbackResponse> getAchievements(String userName) {
if (json == null) {
return null;
}
return gson.fromJson(json, FeedbackResponse.class);
Timber.d(json);
try {
return gson.fromJson(String.valueOf(response.body()), FeedbackResponse.class);
}
catch (Exception e){
return new FeedbackResponse("",0,0,0,new FeaturedImages(0,0),0,"",0);
}


}
return null;
});
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
android:layout_width="match_parent"
app:navigationIcon="@drawable/ic_arrow_back_primary_24dp"
android:background="@color/item_white_background"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:theme="@style/LightAppTheme">
<SearchView
android:id="@+id/searchBox"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_recent_searches.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="@dimen/standard_gap"
android:textColor="@color/black"
android:text="@string/search_commons"
xmlns:android="http://schemas.android.com/apk/res/android" />
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Nov 03 11:02:51 CET 2018
#Sat Dec 08 21:00:44 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip