Skip to content

Commit bc994d1

Browse files
Merge pull request commons-app#4537 from 4D17Y4/master-update
[GSoC] Master rebase
2 parents 70acd7b + 3c18b1e commit bc994d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1230
-235
lines changed

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="fr.free.nrw.commons">
5+
<uses-permission android:name="android.permission.INTERNET"/>
56

67
<uses-permission android:name="android.permission.INTERNET" />
78
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ public static void handleGeoCoordinates(Context context, LatLng latLng) {
178178
public static Bitmap getScreenShot(View view) {
179179
View screenView = view.getRootView();
180180
screenView.setDrawingCacheEnabled(true);
181-
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
182-
screenView.setDrawingCacheEnabled(false);
183-
return bitmap;
181+
Bitmap drawingCache = screenView.getDrawingCache();
182+
if (drawingCache != null) {
183+
Bitmap bitmap = Bitmap.createBitmap(drawingCache);
184+
screenView.setDrawingCacheEnabled(false);
185+
return bitmap;
186+
}
187+
return null;
184188
}
185189

186190
/*

app/src/main/java/fr/free/nrw/commons/contributions/ContributionBoundaryCallback.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class ContributionBoundaryCallback @Inject constructor(
7070
}
7171
)
7272
}else {
73-
compositeDisposable.clear()
73+
if (compositeDisposable != null){
74+
compositeDisposable.clear()
75+
}
7476
}
7577
}
7678

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListFragment.java

+29-29
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
7474
@BindView(R.id.fab_custom_gallery)
7575
FloatingActionButton fabCustomGallery;
7676

77-
@Inject
78-
SystemThemeUtils systemThemeUtils;
77+
@Inject
78+
SystemThemeUtils systemThemeUtils;
7979

8080
@Inject
8181
ContributionController controller;
@@ -265,34 +265,34 @@ private void setListeners() {
265265
});
266266
}
267267

268-
@OnClick(R.id.fab_custom_gallery)
269-
void launchCustomSelector(){
270-
controller.initiateCustomGalleryPickWithPermission(getActivity());
271-
}
272-
273-
private void animateFAB(final boolean isFabOpen) {
274-
this.isFabOpen = !isFabOpen;
275-
if (fabPlus.isShown()) {
276-
if (isFabOpen) {
277-
fabPlus.startAnimation(rotate_backward);
278-
fabCamera.startAnimation(fab_close);
279-
fabGallery.startAnimation(fab_close);
280-
fabCustomGallery.startAnimation(fab_close);
281-
fabCamera.hide();
282-
fabGallery.hide();
283-
fabCustomGallery.hide();
284-
} else {
285-
fabPlus.startAnimation(rotate_forward);
286-
fabCamera.startAnimation(fab_open);
287-
fabGallery.startAnimation(fab_open);
288-
fabCustomGallery.startAnimation(fab_open);
289-
fabCamera.show();
290-
fabGallery.show();
291-
fabCustomGallery.show();
292-
}
293-
this.isFabOpen = !isFabOpen;
268+
@OnClick(R.id.fab_custom_gallery)
269+
void launchCustomSelector(){
270+
controller.initiateCustomGalleryPickWithPermission(getActivity());
271+
}
272+
273+
private void animateFAB(final boolean isFabOpen) {
274+
this.isFabOpen = !isFabOpen;
275+
if (fabPlus.isShown()) {
276+
if (isFabOpen) {
277+
fabPlus.startAnimation(rotate_backward);
278+
fabCamera.startAnimation(fab_close);
279+
fabGallery.startAnimation(fab_close);
280+
fabCustomGallery.startAnimation(fab_close);
281+
fabCamera.hide();
282+
fabGallery.hide();
283+
fabCustomGallery.hide();
284+
} else {
285+
fabPlus.startAnimation(rotate_forward);
286+
fabCamera.startAnimation(fab_open);
287+
fabGallery.startAnimation(fab_open);
288+
fabCustomGallery.startAnimation(fab_open);
289+
fabCamera.show();
290+
fabGallery.show();
291+
fabCustomGallery.show();
292+
}
293+
this.isFabOpen = !isFabOpen;
294+
}
294295
}
295-
}
296296

297297
/**
298298
* Shows welcome message if user has no contributions yet i.e. new user.

app/src/main/java/fr/free/nrw/commons/logging/LogsSender.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.free.nrw.commons.logging;
22

3+
import static org.acra.ACRA.getErrorReporter;
4+
35
import android.content.Context;
46
import android.content.Intent;
57
import android.net.Uri;
@@ -62,6 +64,8 @@ private void sendLogs(Context context, CrashReportData report) {
6264
final Uri logFileUri = getZippedLogFileUri(context, report);
6365
if (logFileUri != null) {
6466
sendEmail(context, logFileUri);
67+
} else {
68+
getErrorReporter().handleSilentException(null);
6569
}
6670
}
6771

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ private void setupImageView() {
546546
image.getHierarchy().setFailureImage(R.drawable.image_placeholder);
547547

548548
DraweeController controller = Fresco.newDraweeControllerBuilder()
549-
.setLowResImageRequest(ImageRequest.fromUri(media.getThumbUrl()))
550-
.setImageRequest(ImageRequest.fromUri(media.getImageUrl()))
549+
.setLowResImageRequest(ImageRequest.fromUri(media != null ? media.getThumbUrl() : null))
550+
.setImageRequest(ImageRequest.fromUri(media != null ? media.getImageUrl() : null))
551551
.setControllerListener(aspectRatioListener)
552552
.setOldController(image.getController())
553553
.build();

app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.java

+111-1
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
package fr.free.nrw.commons.profile;
22

3+
import android.app.AlertDialog;
34
import android.content.Context;
45
import android.content.Intent;
6+
import android.graphics.Bitmap;
7+
import android.net.Uri;
58
import android.os.Bundle;
9+
import android.view.LayoutInflater;
10+
import android.view.Menu;
11+
import android.view.MenuInflater;
12+
import android.view.MenuItem;
13+
import android.view.View;
14+
import android.widget.ImageView;
15+
import android.widget.TextView;
16+
import androidx.appcompat.widget.Toolbar;
17+
import androidx.core.content.FileProvider;
618
import androidx.fragment.app.Fragment;
719
import androidx.fragment.app.FragmentManager;
820
import androidx.viewpager.widget.ViewPager;
921
import butterknife.BindView;
1022
import butterknife.ButterKnife;
1123
import com.google.android.material.tabs.TabLayout;
1224
import fr.free.nrw.commons.R;
25+
import fr.free.nrw.commons.Utils;
1326
import fr.free.nrw.commons.ViewPagerAdapter;
27+
import fr.free.nrw.commons.auth.SessionManager;
1428
import fr.free.nrw.commons.profile.achievements.AchievementsFragment;
1529
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment;
1630
import fr.free.nrw.commons.theme.BaseActivity;
31+
import java.io.File;
32+
import java.io.FileOutputStream;
33+
import java.io.IOException;
1734
import java.util.ArrayList;
1835
import java.util.List;
36+
import javax.inject.Inject;
1937

2038
/**
2139
* This activity will set two tabs, achievements and
@@ -31,6 +49,12 @@ public class ProfileActivity extends BaseActivity {
3149
@BindView(R.id.tab_layout)
3250
TabLayout tabLayout;
3351

52+
@BindView(R.id.toolbar)
53+
Toolbar toolbar;
54+
55+
@Inject
56+
SessionManager sessionManager;
57+
3458
private ViewPagerAdapter viewPagerAdapter;
3559
private AchievementsFragment achievementsFragment;
3660
private LeaderboardFragment leaderboardFragment;
@@ -40,7 +64,9 @@ protected void onCreate(Bundle savedInstanceState) {
4064
super.onCreate(savedInstanceState);
4165
setContentView(R.layout.activity_profile);
4266
ButterKnife.bind(this);
43-
setTitle(R.string.Profile);
67+
setSupportActionBar(toolbar);
68+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
69+
setTitle(sessionManager.getUserName());
4470

4571
supportFragmentManager = getSupportFragmentManager();
4672
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
@@ -49,6 +75,16 @@ protected void onCreate(Bundle savedInstanceState) {
4975
setTabs();
5076
}
5177

78+
/**
79+
* Navigate up event
80+
* @return boolean
81+
*/
82+
@Override
83+
public boolean onSupportNavigateUp() {
84+
onBackPressed();
85+
return true;
86+
}
87+
5288
/**
5389
* Creates a way to change current activity to AchievementActivity
5490
* @param context
@@ -75,10 +111,84 @@ private void setTabs() {
75111
viewPagerAdapter.notifyDataSetChanged();
76112

77113
}
114+
78115
@Override
79116
public void onDestroy() {
80117
super.onDestroy();
81118
compositeDisposable.clear();
82119
}
83120

121+
/**
122+
* To inflate menu
123+
* @param menu Menu
124+
* @return boolean
125+
*/
126+
@Override
127+
public boolean onCreateOptionsMenu(final Menu menu) {
128+
final MenuInflater menuInflater = getMenuInflater();
129+
menuInflater.inflate(R.menu.menu_about, menu);
130+
return super.onCreateOptionsMenu(menu);
131+
}
132+
133+
/**
134+
* To receive the id of selected item and handle further logic for that selected item
135+
* @param item MenuItem
136+
* @return boolean
137+
*/
138+
@Override
139+
public boolean onOptionsItemSelected(final MenuItem item) {
140+
// take screenshot in form of bitmap and show it in Alert Dialog
141+
if (item.getItemId() == R.id.share_app_icon) {
142+
final View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
143+
final Bitmap screenShot = Utils.getScreenShot(rootView);
144+
showAlert(screenShot);
145+
return true;
146+
}
147+
return super.onOptionsItemSelected(item);
148+
}
149+
150+
/**
151+
* It displays the alertDialog with Image of screenshot
152+
* @param screenshot screenshot of the present screen
153+
*/
154+
public void showAlert(final Bitmap screenshot) {
155+
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
156+
final LayoutInflater factory = LayoutInflater.from(this);
157+
final View view = factory.inflate(R.layout.image_alert_layout, null);
158+
final ImageView screenShotImage = view.findViewById(R.id.alert_image);
159+
screenShotImage.setImageBitmap(screenshot);
160+
final TextView shareMessage = view.findViewById(R.id.alert_text);
161+
shareMessage.setText(R.string.achievements_share_message);
162+
alert.setView(view);
163+
alert.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> shareScreen(screenshot));
164+
alert.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel());
165+
alert.show();
166+
}
167+
168+
/**
169+
* To take bitmap and store it temporary storage and share it
170+
* @param bitmap bitmap of screenshot
171+
*/
172+
void shareScreen(final Bitmap bitmap) {
173+
try {
174+
final File file = new File(getExternalCacheDir(), "screen.png");
175+
final FileOutputStream fileOutputStream = new FileOutputStream(file);
176+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
177+
fileOutputStream.flush();
178+
fileOutputStream.close();
179+
file.setReadable(true, false);
180+
181+
final Uri fileUri = FileProvider
182+
.getUriForFile(getApplicationContext(),
183+
getPackageName() + ".provider", file);
184+
grantUriPermission(getPackageName(), fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
185+
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
186+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
187+
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
188+
intent.setType("image/png");
189+
startActivity(Intent.createChooser(intent, getString(R.string.share_image_via)));
190+
} catch (final IOException e) {
191+
e.printStackTrace();
192+
}
193+
}
84194
}

0 commit comments

Comments
 (0)