2025-12-22 16:31:46 +08:00
|
|
|
package com.example.livestreaming;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
2025-12-30 17:33:27 +08:00
|
|
|
import android.view.View;
|
2025-12-22 16:31:46 +08:00
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2025-12-30 17:33:27 +08:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2025-12-22 16:31:46 +08:00
|
|
|
|
|
|
|
|
import com.example.livestreaming.databinding.ActivityFindGameBinding;
|
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
|
|
|
2025-12-30 17:33:27 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
public class FindGameActivity extends AppCompatActivity {
|
|
|
|
|
|
2025-12-30 17:33:27 +08:00
|
|
|
private static final String CATEGORY = "找人玩游戏";
|
2025-12-22 16:31:46 +08:00
|
|
|
private ActivityFindGameBinding binding;
|
2025-12-30 17:33:27 +08:00
|
|
|
private PostAdapter postAdapter;
|
2025-12-22 16:31:46 +08:00
|
|
|
|
|
|
|
|
public static void start(Context context) {
|
|
|
|
|
Intent intent = new Intent(context, FindGameActivity.class);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
binding = ActivityFindGameBinding.inflate(getLayoutInflater());
|
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
|
|
|
|
|
|
setupUI();
|
2025-12-30 17:33:27 +08:00
|
|
|
setupRecyclerView();
|
|
|
|
|
loadPosts();
|
2025-12-22 16:31:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setupUI() {
|
|
|
|
|
binding.backButton.setOnClickListener(v -> finish());
|
|
|
|
|
|
2025-12-30 17:33:27 +08:00
|
|
|
binding.fabPublish.setOnClickListener(v -> {
|
|
|
|
|
PublishPostHelper.showPublishDialog(this, CATEGORY, new PublishPostHelper.PublishCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(Post post) {
|
|
|
|
|
postAdapter.addPost(post);
|
|
|
|
|
binding.recyclerPosts.scrollToPosition(0);
|
|
|
|
|
updateEmptyView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(String error) {}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
BottomNavigationView bottomNavigation = binding.bottomNavInclude.bottomNavigation;
|
|
|
|
|
bottomNavigation.setSelectedItemId(R.id.nav_friends);
|
2025-12-23 15:37:37 +08:00
|
|
|
UnreadMessageManager.updateBadge(bottomNavigation);
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
bottomNavigation.setOnItemSelectedListener(item -> {
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
if (id == R.id.nav_home) {
|
|
|
|
|
startActivity(new Intent(this, MainActivity.class));
|
|
|
|
|
finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (id == R.id.nav_wish_tree) {
|
|
|
|
|
WishTreeActivity.start(this);
|
|
|
|
|
finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (id == R.id.nav_messages) {
|
|
|
|
|
MessagesActivity.start(this);
|
|
|
|
|
finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (id == R.id.nav_profile) {
|
|
|
|
|
ProfileActivity.start(this);
|
|
|
|
|
finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-30 17:33:27 +08:00
|
|
|
|
|
|
|
|
private void setupRecyclerView() {
|
|
|
|
|
postAdapter = new PostAdapter();
|
|
|
|
|
binding.recyclerPosts.setLayoutManager(new LinearLayoutManager(this));
|
|
|
|
|
binding.recyclerPosts.setAdapter(postAdapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadPosts() {
|
|
|
|
|
List<Post> posts = PostManager.getPostsByCategory(this, CATEGORY);
|
|
|
|
|
postAdapter.setPosts(posts);
|
|
|
|
|
updateEmptyView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateEmptyView() {
|
|
|
|
|
if (postAdapter.getItemCount() == 0) {
|
|
|
|
|
binding.emptyView.setVisibility(View.VISIBLE);
|
|
|
|
|
binding.recyclerPosts.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
binding.emptyView.setVisibility(View.GONE);
|
|
|
|
|
binding.recyclerPosts.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-23 15:37:37 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
if (binding != null) {
|
|
|
|
|
BottomNavigationView bottomNav = binding.bottomNavInclude.bottomNavigation;
|
|
|
|
|
bottomNav.setSelectedItemId(R.id.nav_friends);
|
|
|
|
|
UnreadMessageManager.updateBadge(bottomNav);
|
2025-12-30 17:33:27 +08:00
|
|
|
loadPosts();
|
2025-12-23 15:37:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-12-22 16:31:46 +08:00
|
|
|
}
|