Skip to content

Commit

Permalink
Fix receiving API messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Nov 25, 2023
1 parent 313ba3a commit 9224b5d
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public Message(long id, boolean incoming, boolean error, long _timestamp, String
timestamp_int = _timestamp;
Date dt = new Date(TimeUnit.SECONDS.toMillis(_timestamp));
timestamp = new SimpleDateFormat("HH:mm").format(dt);
if(!incoming) {
type = 1;
}
}

public void getSendedId(String response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import uk.openvk.android.refresh.ui.core.fragments.app.settings.VideoSettingsFragment;
import uk.openvk.android.refresh.ui.list.adapters.NewsfeedToolbarSpinnerAdapter;
import uk.openvk.android.refresh.ui.list.items.ToolbarSpinnerItem;
import uk.openvk.android.refresh.ui.view.layouts.ProfileHeader;
import uk.openvk.android.refresh.ui.wrappers.LocaleContextWrapper;

public class AppActivity extends NetworkActivity {
Expand Down Expand Up @@ -427,11 +428,9 @@ public void onClick(View v) {
startQuickSearchActivity();
}
});
if(ovk_api.account == null || ovk_api.account.user == null) {
String profile_name = getResources().getString(R.string.loading);
((TextView) header.findViewById(R.id.profile_name)).setText(profile_name);
header.findViewById(R.id.screen_name).setVisibility(View.GONE);
}
String profile_name = getResources().getString(R.string.loading);
((TextView) header.findViewById(R.id.profile_name)).setText(profile_name);
header.findViewById(R.id.screen_name).setVisibility(View.GONE);
@SuppressLint("CutPasteId") ShapeableImageView avatar = ((ShapeableImageView)
((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0)
.findViewById(R.id.profile_avatar));
Expand Down Expand Up @@ -664,13 +663,28 @@ public Fragment getSelectedFragment() {

@SuppressLint("NotifyDataSetChanged")
public void receiveState(int message, Bundle data) {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
// Handling OpenVK API and UI messages
try {
if (message == HandlerMessages.ACCOUNT_PROFILE_INFO) {
ovk_api.newsfeed.get(ovk_api.wrapper, 25);
ovk_api.users.getAccountUser(ovk_api.wrapper, ovk_api.account.id);
ovk_api.messages.getLongPollServer(ovk_api.wrapper);
ovk_api.messages.getConversations(ovk_api.wrapper);
String profile_name = String.format("%s %s",
ovk_api.account.first_name, ovk_api.account.last_name);
ConstraintLayout header = (ConstraintLayout)
((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0);
((TextView) header.findViewById(R.id.profile_name)).setText(profile_name);
} else if (message == HandlerMessages.ACCOUNT_COUNTERS) {
BottomNavigationView b_navView = findViewById(R.id.bottom_nav_view);
int accentColor;
Expand Down Expand Up @@ -731,12 +745,11 @@ public void receiveState(int message, Bundle data) {
}
} else if (message == HandlerMessages.USERS_GET_ALT) {
ovk_api.account.user = ovk_api.users.getList().get(0);
ovk_api.account.user.downloadAvatar(downloadManager, "high", "account_avatar");
ConstraintLayout header = (ConstraintLayout)
((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0);
ovk_api.account.user.downloadAvatar(ovk_api.dlman, "high", "account_avatar");
String profile_name = String.format("%s %s", ovk_api.account.first_name,
ovk_api.account.last_name);
((TextView) ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0)
.findViewById(R.id.profile_name))
.setText(profile_name);
if(ovk_api.account.user.screen_name != null &&
ovk_api.account.user.screen_name.length() > 0) {
((TextView) ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ public void signIn(String twofactor_code) {
}

public void receiveState(int message, Bundle data) {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if (message == HandlerMessages.AUTHORIZED) {
SharedPreferences.Editor editor = instance_prefs.edit();
Authorization auth = new Authorization(data.getString("response"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ public void setAPIWrapper() {

@SuppressLint("NotifyDataSetChanged")
public void receiveState(int message, Bundle data) {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if (message == HandlerMessages.MESSAGES_GET_HISTORY) {
messagesView = findViewById(R.id.messages_view);
history = conversation.parseHistory(this, data.getString("response"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public void onClick(View view) {

public void receiveState(int message, Bundle data) {
try {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if (message == HandlerMessages.ACCOUNT_PROFILE_INFO) {
if (args.startsWith("id")) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ public void onClick(View view) {

public void receiveState(int message, Bundle data) {
try {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if (message == HandlerMessages.ACCOUNT_PROFILE_INFO) {
if (args.startsWith("club")) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,30 @@ public void switchFragment(String tag) {
if(selectedFragment == null) selectedFragment = getSupportFragmentManager()
.findFragmentByTag("settings");
switch (tag) {
case "settings":
case "settings" -> {
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("settings"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.nav_settings);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(
R.drawable.ic_arrow_back);
break;
case "personalization":
}
case "personalization" -> {
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("personalization"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.pref_personalization);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(
R.drawable.ic_arrow_back);
break;
case "about_app":
}
case "about_app" -> {
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("about_app"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.pref_about_app);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(
R.drawable.ic_arrow_back);
break;
}
}
ft.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ private void sendPost() {

public void receiveState(int message, Bundle data) {
try {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if(message == HandlerMessages.WALL_POST) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.posted_successfully), Toast.LENGTH_LONG).show();
Expand All @@ -210,7 +220,7 @@ public void receiveState(int message, Bundle data) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.posting_access_denied),
Toast.LENGTH_LONG).show();
} else {
} else if(message < 0){
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.posting_error),
Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ private void loadPhoto() {

@SuppressLint("UseCompatLoadingForDrawables")
public void receiveState(int message, Bundle data) {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if(message == HandlerMessages.ACCESS_DENIED_MARSHMALLOW) {
allowPermissionDialog();
} else if(message == HandlerMessages.ORIGINAL_PHOTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ public void onClick(View view) {

public void receiveState(int message, Bundle data) {
try {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if (message == HandlerMessages.ACCOUNT_PROFILE_INFO) {
if (args.startsWith("id")) {
MaterialToolbar appBar = findViewById(R.id.app_toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ private void setAPIWrapper() {
}

public void receiveState(int message, Bundle data) {
if(data.containsKey("address")) {
String activityName = data.getString("address");
if(activityName == null) {
return;
}
boolean isCurrentActivity = activityName.equals(getLocalClassName());
if(!isCurrentActivity) {
return;
}
}
if(message == HandlerMessages.ACCOUNT_PROFILE_INFO) {
ovk_api.account.parse(data.getString("response"), ovk_api.wrapper);
setBottomPanel();
Expand Down
Loading

0 comments on commit 9224b5d

Please sign in to comment.