Merge branch 'master' of http://115.190.64.57:8000/xiaozhang/zhibo
This commit is contained in:
commit
e7649df1af
|
|
@ -4,16 +4,18 @@ import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.example.livestreaming.databinding.ActivityWishTreeBinding;
|
import com.example.livestreaming.databinding.ActivityWishTreeBinding;
|
||||||
|
|
@ -89,47 +91,65 @@ public class WishTreeActivity extends AppCompatActivity {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
cards[i].setOnClickListener(v -> onWishCardClick(index));
|
cards[i].setOnClickListener(v -> onWishCardClick(index));
|
||||||
}
|
}
|
||||||
binding.addWishCard.setOnClickListener(v -> showMakeWishConfirmDialog(-1));
|
binding.addWishCard.setOnClickListener(v -> showMakeWishInputDialog(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onWishCardClick(int index) {
|
private void onWishCardClick(int index) {
|
||||||
if (wishes[index] != null && !wishes[index].isEmpty()) {
|
if (wishes[index] != null && !wishes[index].isEmpty()) {
|
||||||
showViewWishDialog(index);
|
showViewWishDialog(index);
|
||||||
} else {
|
} 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) {
|
private void showMakeWishInputDialog(int index) {
|
||||||
View view = getLayoutInflater().inflate(R.layout.dialog_make_wish, null);
|
Dialog dialog = new Dialog(this);
|
||||||
EditText input = view.findViewById(R.id.editWish);
|
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("写下你的心愿")
|
EditText input = dialog.findViewById(R.id.editWish);
|
||||||
.setView(view)
|
TextView tvCharCount = dialog.findViewById(R.id.tvCharCount);
|
||||||
.setNegativeButton("取消", null)
|
View btnCancel = dialog.findViewById(R.id.btnCancel);
|
||||||
.setPositiveButton("确认", (d, w) -> {
|
View btnMakeWish = dialog.findViewById(R.id.btnMakeWish);
|
||||||
String wish = input.getText().toString().trim();
|
|
||||||
if (!wish.isEmpty()) {
|
// 字数统计
|
||||||
int saveIndex = index >= 0 ? index : findEmptySlot();
|
input.addTextChangedListener(new android.text.TextWatcher() {
|
||||||
if (saveIndex >= 0) {
|
@Override
|
||||||
saveWish(saveIndex, wish);
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||||
showSuccessDialog();
|
@Override
|
||||||
} else {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||||
Toast.makeText(this, "心愿牌已满", Toast.LENGTH_SHORT).show();
|
@Override
|
||||||
}
|
public void afterTextChanged(android.text.Editable s) {
|
||||||
}
|
tvCharCount.setText(s.length() + "/50");
|
||||||
})
|
}
|
||||||
.show();
|
});
|
||||||
|
|
||||||
|
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() {
|
private int findEmptySlot() {
|
||||||
|
|
@ -143,24 +163,47 @@ public class WishTreeActivity extends AppCompatActivity {
|
||||||
Dialog dialog = new Dialog(this);
|
Dialog dialog = new Dialog(this);
|
||||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
dialog.setContentView(R.layout.dialog_wish_success);
|
dialog.setContentView(R.layout.dialog_wish_success);
|
||||||
|
if (dialog.getWindow() != null) {
|
||||||
|
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
dialog.show();
|
dialog.show();
|
||||||
handler.postDelayed(dialog::dismiss, 1500);
|
handler.postDelayed(dialog::dismiss, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showViewWishDialog(int index) {
|
private void showViewWishDialog(int index) {
|
||||||
new AlertDialog.Builder(this)
|
Dialog dialog = new Dialog(this);
|
||||||
.setTitle("我的心愿")
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
.setMessage(wishes[index])
|
dialog.setContentView(R.layout.dialog_view_wish);
|
||||||
.setPositiveButton("关闭", null)
|
if (dialog.getWindow() != null) {
|
||||||
.setNegativeButton("删除心愿", (d, w) -> {
|
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
saveWish(index, "");
|
}
|
||||||
Toast.makeText(this, "心愿已删除", Toast.LENGTH_SHORT).show();
|
|
||||||
})
|
TextView tvContent = dialog.findViewById(R.id.tvWishContent);
|
||||||
.show();
|
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() {
|
private void setupMakeWishButton() {
|
||||||
binding.btnMakeWish.setOnClickListener(v -> showMakeWishConfirmDialog(-1));
|
binding.btnMakeWish.setOnClickListener(v -> showMakeWishInputDialog(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupBottomNav() {
|
private void setupBottomNav() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user