Skip to content

Commit 392b3f6

Browse files
separated profile view activity
1 parent e02ef0a commit 392b3f6

26 files changed

+1119
-262
lines changed

Diff for: LICENSE

+1-41
Original file line numberDiff line numberDiff line change
@@ -618,44 +618,4 @@ an absolute waiver of all civil liability in connection with the
618618
Program, unless a warranty or assumption of liability accompanies a
619619
copy of the Program in return for a fee.
620620

621-
END OF TERMS AND CONDITIONS
622-
623-
How to Apply These Terms to Your New Programs
624-
625-
If you develop a new program, and you want it to be of the greatest
626-
possible use to the public, the best way to achieve this is to make it
627-
free software which everyone can redistribute and change under these terms.
628-
629-
To do so, attach the following notices to the program. It is safest
630-
to attach them to the start of each source file to most effectively
631-
state the exclusion of warranty; and each file should have at least
632-
the "copyright" line and a pointer to where the full notice is found.
633-
634-
InstaGrabber
635-
Copyright (C) 2019 AWAiS <[email protected]>
636-
Copyright (C) 2020 Austin Huang <[email protected]>
637-
Ammar Githam <[email protected]>
638-
639-
This program is free software: you can redistribute it and/or modify
640-
it under the terms of the GNU General Public License as published by
641-
the Free Software Foundation, either version 3 of the License, or
642-
(at your option) any later version.
643-
644-
This program is distributed in the hope that it will be useful,
645-
but WITHOUT ANY WARRANTY; without even the implied warranty of
646-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
647-
GNU General Public License for more details.
648-
649-
You should have received a copy of the GNU General Public License
650-
along with this program. If not, see <http://www.gnu.org/licenses/>.
651-
652-
Also add information on how to contact you by electronic and paper mail.
653-
654-
[we're not terminal program, redacted]
655-
656-
The GNU General Public License does not permit incorporating your program
657-
into proprietary programs. If your program is a subroutine library, you
658-
may consider it more useful to permit linking proprietary applications with
659-
the library. If this is what you want to do, use the GNU Lesser General
660-
Public License instead of this License. But first, please read
661-
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
621+
END OF TERMS AND CONDITIONS

Diff for: app/src/main/AndroidManifest.xml

+10-1
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,23 @@
169169
</activity>
170170

171171
<activity
172-
android:name=".activities.ProfileViewer"
172+
android:name=".activities.ProfilePicViewer"
173173
android:parentActivityName=".activities.Main">
174174

175175
<meta-data
176176
android:name="android.support.PARENT_ACTIVITY"
177177
android:value=".activities.Main" />
178178
</activity>
179179

180+
<activity
181+
android:name=".activities.ProfileViewer"
182+
android:parentActivityName=".activities.PostViewer">
183+
184+
<meta-data
185+
android:name="android.support.PARENT_ACTIVITY"
186+
android:value=".activities.PostViewer" />
187+
</activity>
188+
180189
<activity
181190
android:name=".activities.SavedViewer"
182191
android:parentActivityName=".activities.Main">

Diff for: app/src/main/java/awais/instagrabber/activities/CommentsViewer.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
import android.view.Menu;
1414
import android.view.MenuItem;
1515
import android.view.View;
16-
import android.view.WindowManager;
1716
import android.widget.ArrayAdapter;
1817
import android.widget.Toast;
1918

2019
import androidx.annotation.Nullable;
2120
import androidx.appcompat.app.AlertDialog;
22-
import androidx.appcompat.app.AppCompatActivity;
2321
import androidx.appcompat.widget.SearchView;
2422
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
2523

@@ -39,8 +37,6 @@
3937
import awais.instagrabber.utils.Constants;
4038
import awais.instagrabber.utils.Utils;
4139

42-
import static awais.instagrabber.utils.Utils.settingsHelper;
43-
4440
public final class CommentsViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener {
4541
private CommentsAdapter commentsAdapter;
4642
private CommentModel commentModel;
@@ -117,7 +113,7 @@ public void onResult(final CommentModel[] commentModels) {
117113
if (which == 0) {
118114
searchUsername(profileModel.getUsername());
119115
} else if (which == 1) {
120-
startActivity(new Intent(this, ProfileViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel));
116+
startActivity(new Intent(this, ProfilePicViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel));
121117
} else if (which == 2) {
122118
Utils.copyText(this, profileModel.getUsername());
123119
} else if (which == 3) {
@@ -211,11 +207,10 @@ else if (v == commentsBinding.commentCancelParent) {
211207
};
212208

213209
private void searchUsername(final String text) {
214-
if (Main.scanHack != null) {
215-
Main.scanHack.onResult(text);
216-
setResult(6969);
217-
finish();
218-
}
210+
startActivity(
211+
new Intent(getApplicationContext(), ProfileViewer.class)
212+
.putExtra(Constants.EXTRAS_USERNAME, text)
213+
);
219214
}
220215

221216
@Override

Diff for: app/src/main/java/awais/instagrabber/activities/FollowViewer.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
7777
final Object tag = v.getTag();
7878
if (tag instanceof FollowModel) {
7979
model = (FollowModel) tag;
80-
Main.scanHack.onResult(model.getUsername());
81-
finish();
80+
startActivity(
81+
new Intent(getApplicationContext(), ProfileViewer.class)
82+
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
83+
);
8284
}
8385
};
8486

Diff for: app/src/main/java/awais/instagrabber/activities/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected void onCreate(@Nullable final Bundle bundle) {
195195
profileDialogListener = (dialog, which) -> {
196196
final Intent intent;
197197
if (which == 0 || storyModels == null || storyModels.length < 1) {
198-
intent = new Intent(this, ProfileViewer.class).putExtra(
198+
intent = new Intent(this, ProfilePicViewer.class).putExtra(
199199
((hashtagModel != null) ? Constants.EXTRAS_HASHTAG : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)),
200200
((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel)));
201201
}

Diff for: app/src/main/java/awais/instagrabber/activities/PostViewer.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public boolean onTouch(final View v, final MotionEvent event) {
122122
if (which == 0) {
123123
searchUsername(username);
124124
} else if (profileModel != null && which == 1) {
125-
startActivity(new Intent(this, ProfileViewer.class)
125+
startActivity(new Intent(this, ProfilePicViewer.class)
126126
.putExtra(Constants.EXTRAS_PROFILE, profileModel));
127127
}
128128
};
@@ -432,13 +432,10 @@ else if (postModel.getPostId() != null)
432432
}
433433

434434
private void searchUsername(final String text) {
435-
if (Main.scanHack != null) {
436-
Main.scanHack.onResult(text);
437-
setResult(6969);
438-
Intent intent = new Intent(getApplicationContext(), Main.class);
439-
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
440-
startActivity(intent);
441-
}
435+
startActivity(
436+
new Intent(getApplicationContext(), ProfileViewer.class)
437+
.putExtra(Constants.EXTRAS_USERNAME, text)
438+
);
442439
}
443440

444441
private void setupVideo() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
package awais.instagrabber.activities;
2+
3+
import android.content.Intent;
4+
import android.graphics.Bitmap;
5+
import android.graphics.drawable.BitmapDrawable;
6+
import android.graphics.drawable.Drawable;
7+
import android.os.AsyncTask;
8+
import android.os.Bundle;
9+
import android.os.Environment;
10+
import android.view.Menu;
11+
import android.view.MenuItem;
12+
import android.view.View;
13+
import android.widget.Toast;
14+
15+
import androidx.annotation.Nullable;
16+
import androidx.fragment.app.FragmentManager;
17+
18+
import com.bumptech.glide.Glide;
19+
import com.bumptech.glide.RequestManager;
20+
import com.bumptech.glide.load.DataSource;
21+
import com.bumptech.glide.load.engine.GlideException;
22+
import com.bumptech.glide.request.RequestListener;
23+
import com.bumptech.glide.request.target.Target;
24+
25+
import java.io.File;
26+
27+
import awais.instagrabber.R;
28+
import awais.instagrabber.asyncs.DownloadAsync;
29+
import awais.instagrabber.asyncs.ProfilePictureFetcher;
30+
import awais.instagrabber.databinding.ActivityProfilepicBinding;
31+
import awais.instagrabber.interfaces.FetchListener;
32+
import awais.instagrabber.models.HashtagModel;
33+
import awais.instagrabber.models.LocationModel;
34+
import awais.instagrabber.models.ProfileModel;
35+
import awais.instagrabber.utils.Constants;
36+
import awais.instagrabber.utils.Utils;
37+
38+
public final class ProfilePicViewer extends BaseLanguageActivity {
39+
private ActivityProfilepicBinding profileBinding;
40+
private ProfileModel profileModel;
41+
private HashtagModel hashtagModel;
42+
private LocationModel locationModel;
43+
private MenuItem menuItemDownload;
44+
private String profilePicUrl;
45+
private FragmentManager fragmentManager;
46+
private FetchListener<String> fetchListener;
47+
private boolean errorHandled = false;
48+
private boolean fallbackToProfile = false;
49+
private boolean destroyed = false;
50+
51+
@Override
52+
protected void onCreate(@Nullable final Bundle savedInstanceState) {
53+
super.onCreate(savedInstanceState);
54+
profileBinding = ActivityProfilepicBinding.inflate(getLayoutInflater());
55+
setContentView(profileBinding.getRoot());
56+
57+
setSupportActionBar(profileBinding.toolbar.toolbar);
58+
59+
final Intent intent = getIntent();
60+
if (intent == null || (!intent.hasExtra(Constants.EXTRAS_PROFILE) && !intent.hasExtra(Constants.EXTRAS_HASHTAG) && !intent.hasExtra(Constants.EXTRAS_LOCATION))
61+
|| ((profileModel = (ProfileModel) intent.getSerializableExtra(Constants.EXTRAS_PROFILE)) == null
62+
&& (hashtagModel = (HashtagModel) intent.getSerializableExtra(Constants.EXTRAS_HASHTAG)) == null
63+
&& (locationModel = (LocationModel) intent.getSerializableExtra(Constants.EXTRAS_LOCATION)) == null)) {
64+
Utils.errorFinish(this);
65+
return;
66+
}
67+
68+
fragmentManager = getSupportFragmentManager();
69+
70+
final String id = hashtagModel != null ? hashtagModel.getId() : (locationModel != null ? locationModel.getId() : profileModel.getId());
71+
final String username = hashtagModel != null ? hashtagModel.getName() : (locationModel != null ? locationModel.getName() : profileModel.getUsername());
72+
73+
profileBinding.toolbar.toolbar.setTitle(username);
74+
75+
profileBinding.progressView.setVisibility(View.VISIBLE);
76+
profileBinding.imageViewer.setVisibility(View.VISIBLE);
77+
78+
profileBinding.imageViewer.setZoomable(true);
79+
profileBinding.imageViewer.setZoomTransitionDuration(420);
80+
profileBinding.imageViewer.setMaximumScale(7.2f);
81+
82+
fetchListener = profileUrl -> {
83+
profilePicUrl = profileUrl;
84+
85+
if (!fallbackToProfile && Utils.isEmpty(profilePicUrl)) {
86+
fallbackToProfile = true;
87+
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
88+
return;
89+
}
90+
91+
if (errorHandled && fallbackToProfile || Utils.isEmpty(profilePicUrl))
92+
profilePicUrl = hashtagModel != null ? hashtagModel.getSdProfilePic() : (locationModel != null ? locationModel.getSdProfilePic() : profileModel.getHdProfilePic());
93+
94+
if (destroyed == true) return;
95+
96+
final RequestManager glideRequestManager = Glide.with(this);
97+
98+
glideRequestManager.load(profilePicUrl).addListener(new RequestListener<Drawable>() {
99+
@Override
100+
public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target<Drawable> target, final boolean isFirstResource) {
101+
fallbackToProfile = true;
102+
if (!errorHandled) {
103+
errorHandled = true;
104+
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null))
105+
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
106+
} else {
107+
glideRequestManager.load(profilePicUrl).into(profileBinding.imageViewer);
108+
showImageInfo();
109+
}
110+
profileBinding.progressView.setVisibility(View.GONE);
111+
return false;
112+
}
113+
114+
@Override
115+
public boolean onResourceReady(final Drawable resource, final Object model, final Target<Drawable> target, final DataSource dataSource, final boolean isFirstResource) {
116+
if (menuItemDownload != null) menuItemDownload.setEnabled(true);
117+
showImageInfo();
118+
profileBinding.progressView.setVisibility(View.GONE);
119+
return false;
120+
}
121+
122+
private void showImageInfo() {
123+
final Drawable drawable = profileBinding.imageViewer.getDrawable();
124+
if (drawable != null) {
125+
final StringBuilder info = new StringBuilder(getString(R.string.profile_viewer_imageinfo, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()));
126+
if (drawable instanceof BitmapDrawable) {
127+
final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
128+
if (bitmap != null) {
129+
final String colorDepthPrefix = getString(R.string.profile_viewer_colordepth_prefix);
130+
switch (bitmap.getConfig()) {
131+
case ALPHA_8:
132+
info.append(colorDepthPrefix).append(" 8-bits(A)");
133+
break;
134+
case RGB_565:
135+
info.append(colorDepthPrefix).append(" 16-bits-A");
136+
break;
137+
case ARGB_4444:
138+
info.append(colorDepthPrefix).append(" 16-bits+A");
139+
break;
140+
case ARGB_8888:
141+
info.append(colorDepthPrefix).append(" 32-bits+A");
142+
break;
143+
case RGBA_F16:
144+
info.append(colorDepthPrefix).append(" 64-bits+A");
145+
break;
146+
case HARDWARE:
147+
info.append(colorDepthPrefix).append(" auto");
148+
break;
149+
}
150+
}
151+
}
152+
profileBinding.imageInfo.setText(info);
153+
profileBinding.imageInfo.setVisibility(View.VISIBLE);
154+
}
155+
}
156+
}).into(profileBinding.imageViewer);
157+
};
158+
159+
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null))
160+
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
161+
}
162+
163+
private void downloadProfilePicture() {
164+
int error = 0;
165+
166+
if (profileModel != null) {
167+
final File dir = new File(Environment.getExternalStorageDirectory(), "Download");
168+
if (dir.exists() || dir.mkdirs()) {
169+
170+
final File saveFile = new File(dir, profileModel.getUsername() + '_' + System.currentTimeMillis()
171+
+ Utils.getExtensionFromModel(profilePicUrl, profileModel));
172+
173+
new DownloadAsync(this,
174+
profilePicUrl,
175+
saveFile,
176+
result -> {
177+
final int toastRes = result != null && result.exists() ?
178+
R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file;
179+
Toast.makeText(this, toastRes, Toast.LENGTH_SHORT).show();
180+
}).setItems(null, profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
181+
} else error = 1;
182+
} else error = 2;
183+
184+
if (error == 1) Toast.makeText(this, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show();
185+
else if (error == 2) Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
186+
}
187+
188+
@Override
189+
protected void onDestroy() {
190+
super.onDestroy();
191+
getDelegate().onDestroy();
192+
destroyed = true;
193+
}
194+
195+
@Override
196+
public boolean onCreateOptionsMenu(final Menu menu) {
197+
getMenuInflater().inflate(R.menu.menu, menu);
198+
199+
final MenuItem.OnMenuItemClickListener menuItemClickListener = item -> {
200+
if (item == menuItemDownload) {
201+
downloadProfilePicture();
202+
}
203+
return true;
204+
};
205+
206+
menu.findItem(R.id.action_search).setVisible(false);
207+
menuItemDownload = menu.findItem(R.id.action_download);
208+
menuItemDownload.setVisible(true);
209+
menuItemDownload.setEnabled(false);
210+
menuItemDownload.setOnMenuItemClickListener(menuItemClickListener);
211+
212+
return true;
213+
}
214+
}

0 commit comments

Comments
 (0)