Skip to content

Commit

Permalink
Build 200: Fix uploading photo from Gallery app and add autohiding ac…
Browse files Browse the repository at this point in the history
…count menu
  • Loading branch information
tretdm committed Aug 1, 2023
1 parent 7a0a3e3 commit 3d6e6ed
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 111 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ android {
minSdkVersion 7
//noinspection GradleDependency,OldTargetApi
targetSdkVersion 29
versionCode 199
versionName "1.1.199-pbeta"
versionCode 200
versionName "1.1.200-beta"
}
buildTypes {
release {
Expand All @@ -87,8 +87,8 @@ android {
minSdkVersion 7
//noinspection OldTargetApi
targetSdkVersion 29
versionCode 199
versionName "1.1.199-pbeta.d"
versionCode 200
versionName "1.1.200-beta"
signingConfig signingConfigs.debug
}
releaseConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,45 @@ private void createSlidingMenu() {
}
menu = new SlidingMenu(this);
Global.setSlidingMenu(this, slidingmenuLayout, menu);
menu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
@Override
public void onClosed() {
if(slidingmenuLayout.showAccountMenu) {
slidingmenuLayout.toogleAccountMenu();
}
}
});
} else {
try {
slidingmenuLayout = findViewById(R.id.sliding_menu);
slidingmenuLayout.setAccountProfileListener(this);
slidingmenuLayout.setVisibility(View.VISIBLE);
slidingmenuLayout.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if(visibility == View.GONE) {
if (slidingmenuLayout.showAccountMenu) {
slidingmenuLayout.toogleAccountMenu();
}
}
}
});
} catch (Exception ex) {
while(slidingmenuLayout == null) {
slidingmenuLayout = new SlidingMenuLayout(this);
}
((OvkApplication) getApplicationContext()).isTablet = false;
menu = new SlidingMenu(this);
Global.setSlidingMenu(this, slidingmenuLayout, menu);
menu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
@Override
public void onClosed() {
if(slidingmenuLayout.showAccountMenu) {
slidingmenuLayout.toogleAccountMenu();
}
}
});
}
}
slidingmenuLayout.setProfileName(getResources().getString(R.string.loading));
Expand Down Expand Up @@ -1004,10 +1031,15 @@ public void onClick(View view) {
profileFragment.setCounter(ovk_api.user, "friends", ovk_api.friends.count);
}
} else if(message == HandlerMessages.MESSAGES_CONVERSATIONS) {
conversationsFragment.createAdapter(this, conversations, ovk_api.account);
if (global_prefs.getString("current_screen", "").equals("messages")) {
if(conversations.size() > 0) {
conversationsFragment.createAdapter(this, conversations, ovk_api.account);
if (global_prefs.getString("current_screen", "").equals("messages")) {
progressLayout.setVisibility(View.GONE);
findViewById(R.id.app_fragment).setVisibility(View.VISIBLE);
}
} else {
progressLayout.setVisibility(View.GONE);
findViewById(R.id.app_fragment).setVisibility(View.VISIBLE);
setErrorPage(data, "ovk", message, false);
}
} else if(message == HandlerMessages.LIKES_ADD) {
if (global_prefs.getString("current_screen", "").equals("newsfeed")) {
Expand Down Expand Up @@ -1097,10 +1129,15 @@ public void onClick(View view) {
} else if(message == HandlerMessages.WALL_REPOST) {
Toast.makeText(this, getResources().getString(R.string.repost_ok_wall), Toast.LENGTH_LONG).show();
} else if(message == HandlerMessages.NOTES_GET) {
notesFragment.createAdapter(this, ovk_api.notes.list);
if (global_prefs.getString("current_screen", "").equals("notes")) {
if(ovk_api.notes.list.size() > 0) {
notesFragment.createAdapter(this, ovk_api.notes.list);
if (global_prefs.getString("current_screen", "").equals("notes")) {
progressLayout.setVisibility(View.GONE);
findViewById(R.id.app_fragment).setVisibility(View.VISIBLE);
}
} else {
progressLayout.setVisibility(View.GONE);
findViewById(R.id.app_fragment).setVisibility(View.VISIBLE);
setErrorPage(data, "ovk", message, false);
}
} else if(message == HandlerMessages.OVK_CHECK_HTTP) {
mainSettingsFragment.setConnectionType(
Expand Down Expand Up @@ -1206,12 +1243,20 @@ private void setErrorPage(Bundle data, String icon, int reason, boolean showRetr
errorLayout.setRetryAction(this);
errorLayout.setReason(reason);
if (icon.equals("ovk")) {
if(((Spinner) ab_layout.findViewById(R.id.spinner)).getSelectedItemPosition() == 0) {
if(reason == HandlerMessages.NOTES_GET) {
errorLayout.setTitle(
getResources().getString(R.string.local_newsfeed_no_posts));
} else {
getResources().getString(R.string.no_notes));
} else if(reason == HandlerMessages.MESSAGES_CONVERSATIONS) {
errorLayout.setTitle(
getResources().getString(R.string.no_news));
getResources().getString(R.string.no_messages));
} else {
if (((Spinner) ab_layout.findViewById(R.id.spinner)).getSelectedItemPosition() == 0) {
errorLayout.setTitle(
getResources().getString(R.string.local_newsfeed_no_posts));
} else {
errorLayout.setTitle(
getResources().getString(R.string.no_news));
}
}
} else {
errorLayout.setTitle(getResources().getString(R.string.err_text));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
Expand Down Expand Up @@ -161,11 +162,10 @@ private void setUiListeners() {
findViewById(R.id.newpost_btn_photo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
getResources().getString(R.string.add_photo_gallery)), 4);
startActivityForResult(intent, 4);
}
});
}
Expand Down Expand Up @@ -403,21 +403,21 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
return;
}
Uri uri = data.getData();
String path = uriToFilename(uri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
uploadFile(path);
try {
String path = uriToFilename(uri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
uploadFile(path);
} else {
Global.allowPermissionDialog(this, true);
}
} else {
Global.allowPermissionDialog(this, true);
}
} else {
try {
uploadFile(path);
} catch (Exception ex) {
ex.printStackTrace();
Toast.makeText(this, R.string.error, Toast.LENGTH_LONG).show();
}
} catch (Exception ex) {
ex.printStackTrace();
Toast.makeText(this, R.string.error, Toast.LENGTH_LONG).show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,43 +282,45 @@ public void onClick(View view) {

public void loadAvatar(User user, String quality) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(
String.format("%s/%s/photos_cache/profile_avatars/avatar_%s",
getContext().getCacheDir(), instance, user.id), options);
switch (quality) {
case "medium":
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_msize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
case "high":
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_hsize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
default:
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_osize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
if (getContext() != null) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(
String.format("%s/%s/photos_cache/profile_avatars/avatar_%s",
getContext().getCacheDir(), instance, user.id), options);
switch (quality) {
case "medium":
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_msize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
case "high":
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_hsize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
default:
if (bitmap != null) {
user.avatar = bitmap;
} else if (user.avatar_osize_url.length() > 0) {
user.avatar = null;
} else {
user.avatar = null;
}
break;
}
if (user.avatar != null)
((ImageView) view.findViewById(R.id.profile_photo)).setImageBitmap(user.avatar);
}
if (user.avatar != null)
((ImageView) view.findViewById(R.id.profile_photo)).setImageBitmap(user.avatar);
} catch (OutOfMemoryError ex) {
} catch(OutOfMemoryError ex){
ex.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SlidingMenuLayout extends LinearLayout {

private int accountMenuTargetHeight;
private String instance;
private boolean showAccountMenu;
public boolean showAccountMenu;

public SlidingMenuLayout(final Context context) {
super(context);
Expand Down Expand Up @@ -172,7 +172,7 @@ public void loadAccountAvatar(Account account, String quality) {
}
}

private void toogleAccountMenu() {
public void toogleAccountMenu() {
final ListView account_menu_view = findViewById(R.id.account_menu_view);
accountMenuTargetHeight = (int) (account_menu_view.getAdapter().getCount() *
((47 * (getResources().getDisplayMetrics().scaledDensity)) +
Expand Down
Loading

0 comments on commit 3d6e6ed

Please sign in to comment.