|
22 | 22 | import android.util.Log;
|
23 | 23 | import android.widget.Button;
|
24 | 24 | import android.widget.EditText;
|
| 25 | +import android.widget.Toast; |
25 | 26 |
|
26 | 27 | import androidx.annotation.Nullable;
|
27 | 28 | import androidx.appcompat.app.AppCompatActivity;
|
28 | 29 |
|
29 | 30 | import com.blankj.utilcode.util.StringUtils;
|
30 | 31 |
|
| 32 | +import org.apache.commons.io.FileUtils; |
| 33 | + |
| 34 | +import java.io.File; |
| 35 | + |
31 | 36 | /**
|
32 | 37 | * 追加到日记的快捷方式.
|
33 | 38 | *
|
@@ -65,12 +70,23 @@ private void setupFullScreenInput() {
|
65 | 70 | final EditText input = findViewById(R.id.full_screen_input);
|
66 | 71 | input.requestFocus();
|
67 | 72 |
|
68 |
| - |
69 | 73 | final Button submitButton = findViewById(R.id.submit_button);
|
70 | 74 | submitButton.setOnClickListener(v -> {
|
71 |
| - String userInput = input.getText().toString(); |
72 |
| - Log.i("shortcut", "User input: " + userInput); |
73 |
| - // Handle the user input here |
| 75 | + final String userInput = input.getText().toString().trim(); |
| 76 | + if (StringUtils.isEmpty(userInput)) { |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + final long now = System.currentTimeMillis(); |
| 81 | + final String dailynotesDir = getExternalFilesDir(null).getAbsolutePath() + "/home/shortcuts/ailynotes/"; |
| 82 | + new File(dailynotesDir).mkdirs(); |
| 83 | + final File f = new File(dailynotesDir, now + ".md"); |
| 84 | + try { |
| 85 | + FileUtils.writeStringToFile(f, userInput, "UTF-8"); |
| 86 | + } catch (final Exception e) { |
| 87 | + Log.e("shortcut", "Failed to write to file", e); |
| 88 | + Toast.makeText(this, "Failed to write to file [" + e.getMessage() + "]", Toast.LENGTH_LONG).show(); |
| 89 | + } |
74 | 90 |
|
75 | 91 | finish();
|
76 | 92 | });
|
|
0 commit comments