Compare commits
2 Commits
3e9a65af3f
...
2d88a55348
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d88a55348 | ||
|
|
dbd9a04c9b |
|
|
@ -4,16 +4,18 @@ import android.app.Dialog;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.livestreaming.databinding.ActivityWishTreeBinding;
|
||||
|
|
@ -89,47 +91,65 @@ public class WishTreeActivity extends AppCompatActivity {
|
|||
final int index = i;
|
||||
cards[i].setOnClickListener(v -> onWishCardClick(index));
|
||||
}
|
||||
binding.addWishCard.setOnClickListener(v -> showMakeWishConfirmDialog(-1));
|
||||
binding.addWishCard.setOnClickListener(v -> showMakeWishInputDialog(-1));
|
||||
}
|
||||
|
||||
private void onWishCardClick(int index) {
|
||||
if (wishes[index] != null && !wishes[index].isEmpty()) {
|
||||
showViewWishDialog(index);
|
||||
} else {
|
||||
showMakeWishConfirmDialog(index);
|
||||
showMakeWishInputDialog(index);
|
||||
}
|
||||
}
|
||||
|
||||
private void showMakeWishConfirmDialog(int index) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("许愿确认")
|
||||
.setMessage("是否要在这里许下心愿?")
|
||||
.setNegativeButton("取消", null)
|
||||
.setPositiveButton("进行许愿", (d, w) -> showMakeWishInputDialog(index))
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showMakeWishInputDialog(int index) {
|
||||
View view = getLayoutInflater().inflate(R.layout.dialog_make_wish, null);
|
||||
EditText input = view.findViewById(R.id.editWish);
|
||||
Dialog dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.dialog_make_wish);
|
||||
if (dialog.getWindow() != null) {
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
// 设置对话框宽度为屏幕宽度的85%
|
||||
int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.85);
|
||||
dialog.getWindow().setLayout(width, android.view.WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("写下你的心愿")
|
||||
.setView(view)
|
||||
.setNegativeButton("取消", null)
|
||||
.setPositiveButton("确认", (d, w) -> {
|
||||
String wish = input.getText().toString().trim();
|
||||
if (!wish.isEmpty()) {
|
||||
int saveIndex = index >= 0 ? index : findEmptySlot();
|
||||
if (saveIndex >= 0) {
|
||||
saveWish(saveIndex, wish);
|
||||
showSuccessDialog();
|
||||
} else {
|
||||
Toast.makeText(this, "心愿牌已满", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
||||
EditText input = dialog.findViewById(R.id.editWish);
|
||||
TextView tvCharCount = dialog.findViewById(R.id.tvCharCount);
|
||||
View btnCancel = dialog.findViewById(R.id.btnCancel);
|
||||
View btnMakeWish = dialog.findViewById(R.id.btnMakeWish);
|
||||
|
||||
// 字数统计
|
||||
input.addTextChangedListener(new android.text.TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
@Override
|
||||
public void afterTextChanged(android.text.Editable s) {
|
||||
tvCharCount.setText(s.length() + "/50");
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
btnMakeWish.setOnClickListener(v -> {
|
||||
String wish = input.getText().toString().trim();
|
||||
if (!wish.isEmpty()) {
|
||||
int saveIndex = index >= 0 ? index : findEmptySlot();
|
||||
if (saveIndex >= 0) {
|
||||
saveWish(saveIndex, wish);
|
||||
dialog.dismiss();
|
||||
showSuccessDialog();
|
||||
} else {
|
||||
Toast.makeText(this, "心愿牌已满", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, "请输入心愿内容", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private int findEmptySlot() {
|
||||
|
|
@ -143,24 +163,47 @@ public class WishTreeActivity extends AppCompatActivity {
|
|||
Dialog dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.dialog_wish_success);
|
||||
if (dialog.getWindow() != null) {
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
dialog.show();
|
||||
handler.postDelayed(dialog::dismiss, 1500);
|
||||
}
|
||||
|
||||
private void showViewWishDialog(int index) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("我的心愿")
|
||||
.setMessage(wishes[index])
|
||||
.setPositiveButton("关闭", null)
|
||||
.setNegativeButton("删除心愿", (d, w) -> {
|
||||
saveWish(index, "");
|
||||
Toast.makeText(this, "心愿已删除", Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
.show();
|
||||
Dialog dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.dialog_view_wish);
|
||||
if (dialog.getWindow() != null) {
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
TextView tvContent = dialog.findViewById(R.id.tvWishContent);
|
||||
ImageView btnClose = dialog.findViewById(R.id.btnClose);
|
||||
TextView btnDelete = dialog.findViewById(R.id.btnDeleteWish);
|
||||
TextView btnComplete = dialog.findViewById(R.id.btnCompleteWish);
|
||||
|
||||
tvContent.setText(wishes[index]);
|
||||
|
||||
btnClose.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
btnDelete.setOnClickListener(v -> {
|
||||
saveWish(index, "");
|
||||
Toast.makeText(this, "心愿已删除", Toast.LENGTH_SHORT).show();
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
btnComplete.setOnClickListener(v -> {
|
||||
saveWish(index, "");
|
||||
Toast.makeText(this, "恭喜愿望达成!", Toast.LENGTH_SHORT).show();
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void setupMakeWishButton() {
|
||||
binding.btnMakeWish.setOnClickListener(v -> showMakeWishConfirmDialog(-1));
|
||||
binding.btnMakeWish.setOnClickListener(v -> showMakeWishInputDialog(-1));
|
||||
}
|
||||
|
||||
private void setupBottomNav() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user