2727import android .os .Build ;
2828import android .os .Bundle ;
2929import android .view .MenuItem ;
30- import android .view .View ;
31- import android .view .View .OnClickListener ;
3230import android .widget .Button ;
3331import android .widget .TextView ;
3432
5149import androidx .fragment .app .Fragment ;
5250import androidx .fragment .app .FragmentManager ;
5351import androidx .fragment .app .FragmentTransaction ;
52+ import butterknife .BindView ;
53+ import butterknife .ButterKnife ;
54+ import butterknife .OnClick ;
55+ import butterknife .Unbinder ;
5456
5557
5658public class LogHistoryActivity extends ToolbarActivity {
@@ -63,52 +65,44 @@ public class LogHistoryActivity extends ToolbarActivity {
6365
6466 private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT" ;
6567
66- private String mLogPath = Log_OC .getLogPath ();
67- private File logDIR ;
68- private String mLogText ;
68+ private Unbinder unbinder ;
69+
70+ private String logPath = Log_OC .getLogPath ();
71+ private File logDir ;
72+ private String logText ;
6973
74+ @ BindView (R .id .deleteLogHistoryButton )
75+ Button deleteHistoryButton ;
76+
77+ @ BindView (R .id .sendLogHistoryButton )
78+ Button sendHistoryButton ;
79+
80+ @ BindView (R .id .logTV )
81+ TextView logTV ;
7082
7183 @ Override
7284 protected void onCreate (Bundle savedInstanceState ) {
7385 super .onCreate (savedInstanceState );
7486
7587 setContentView (R .layout .log_send_file );
88+ unbinder = ButterKnife .bind (this );
89+
7690 setupToolbar ();
7791
7892 setTitle (getText (R .string .actionbar_logger ));
7993 if (getSupportActionBar () != null ) {
8094 getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
8195 }
82- Button deleteHistoryButton = findViewById (R .id .deleteLogHistoryButton );
83- Button sendHistoryButton = findViewById (R .id .sendLogHistoryButton );
96+
8497 sendHistoryButton .getBackground ().setColorFilter (ThemeUtils .primaryColor (this ), PorterDuff .Mode .SRC_ATOP );
8598 deleteHistoryButton .setTextColor (ThemeUtils .primaryColor (this , true ));
86- TextView logTV = findViewById (R .id .logTV );
87-
88- deleteHistoryButton .setOnClickListener (new OnClickListener () {
89-
90- @ Override
91- public void onClick (View v ) {
92-
93- Log_OC .deleteHistoryLogging ();
94- finish ();
95- }
96- });
97-
98- sendHistoryButton .setOnClickListener (new OnClickListener () {
99-
100- @ Override
101- public void onClick (View v ) {
102- sendMail ();
103- }
104- });
10599
106100 if (savedInstanceState == null ) {
107- if (mLogPath != null ) {
108- logDIR = new File (mLogPath );
101+ if (logPath != null ) {
102+ logDir = new File (logPath );
109103 }
110104
111- if (logDIR != null && logDIR .isDirectory ()) {
105+ if (logDir != null && logDir .isDirectory ()) {
112106 // Show a dialog while log data is being loaded
113107 showLoadingDialog ();
114108
@@ -117,8 +111,8 @@ public void onClick(View v) {
117111 task .execute ();
118112 }
119113 } else {
120- mLogText = savedInstanceState .getString (KEY_LOG_TEXT );
121- logTV .setText (mLogText );
114+ logText = savedInstanceState .getString (KEY_LOG_TEXT );
115+ logTV .setText (logText );
122116 }
123117 }
124118
@@ -136,18 +130,24 @@ public boolean onOptionsItemSelected(MenuItem item) {
136130 return retval ;
137131 }
138132
133+ @ OnClick (R .id .deleteLogHistoryButton )
134+ void deleteHistoryLogging () {
135+ Log_OC .deleteHistoryLogging ();
136+ finish ();
137+ }
139138
140139 /**
141140 * Start activity for sending email with logs attached
142141 */
143- private void sendMail () {
142+ @ OnClick (R .id .sendLogHistoryButton )
143+ void sendMail () {
144144 String emailAddress = getString (R .string .mail_logger );
145145
146146 ArrayList <Uri > uris = new ArrayList <>();
147147
148148 // Convert from paths to Android friendly Parcelable Uri's
149149 for (String file : Log_OC .getLogFileNames ()) {
150- File logFile = new File (mLogPath , file );
150+ File logFile = new File (logPath , file );
151151 if (logFile .exists ()) {
152152 if (Build .VERSION .SDK_INT < Build .VERSION_CODES .N ) {
153153 uris .add (Uri .fromFile (logFile ));
@@ -168,7 +168,7 @@ private void sendMail() {
168168 try {
169169 startActivity (intent );
170170 } catch (ActivityNotFoundException e ) {
171- Snackbar .make (findViewById (android .R .id .content ),R .string .log_send_no_mail_app ,Snackbar .LENGTH_LONG ).show ();
171+ Snackbar .make (findViewById (android .R .id .content ), R .string .log_send_no_mail_app , Snackbar .LENGTH_LONG ).show ();
172172 Log_OC .i (TAG , "Could not find app for sending log history." );
173173 }
174174
@@ -182,7 +182,7 @@ private class LoadingLogTask extends AsyncTask<String, Void, String> {
182182
183183 LoadingLogTask (TextView logTV ) {
184184 // Use of a WeakReference to ensure the TextView can be garbage collected
185- textViewReference = new WeakReference <>(logTV );
185+ textViewReference = new WeakReference <>(logTV );
186186 }
187187
188188 protected String doInBackground (String ... args ) {
@@ -193,8 +193,8 @@ protected void onPostExecute(String result) {
193193 if (result != null ) {
194194 final TextView logTV = textViewReference .get ();
195195 if (logTV != null ) {
196- mLogText = result ;
197- logTV .setText (mLogText );
196+ logText = result ;
197+ logTV .setText (logText );
198198 dismissLoadingDialog ();
199199 }
200200 }
@@ -214,8 +214,8 @@ private String readLogFile() {
214214 try {
215215 String line ;
216216
217- for (int i = logFileName .length - 1 ; i >= 0 ; i --) {
218- File file = new File (mLogPath , logFileName [i ]);
217+ for (int i = logFileName .length - 1 ; i >= 0 ; i --) {
218+ File file = new File (logPath , logFileName [i ]);
219219 if (file .exists ()) {
220220 // Check if FileReader is ready
221221 try (InputStreamReader inputStreamReader = new InputStreamReader (new FileInputStream (file ),
@@ -231,8 +231,7 @@ private String readLogFile() {
231231 }
232232 }
233233 }
234- }
235- catch (IOException e ) {
234+ } catch (IOException e ) {
236235 Log_OC .d (TAG , e .getMessage ());
237236
238237 } finally {
@@ -248,7 +247,7 @@ private String readLogFile() {
248247
249248 return text .toString ();
250249 }
251- }
250+ }
252251
253252 /**
254253 * Show loading dialog
@@ -264,7 +263,7 @@ public void showLoadingDialog() {
264263 /**
265264 * Dismiss loading dialog
266265 */
267- public void dismissLoadingDialog (){
266+ public void dismissLoadingDialog () {
268267 Fragment frag = getSupportFragmentManager ().findFragmentByTag (DIALOG_WAIT_TAG );
269268 if (frag != null ) {
270269 LoadingDialog loading = (LoadingDialog ) frag ;
@@ -278,7 +277,13 @@ protected void onSaveInstanceState(Bundle outState) {
278277
279278 if (isChangingConfigurations ()) {
280279 // global state
281- outState .putString (KEY_LOG_TEXT , mLogText );
280+ outState .putString (KEY_LOG_TEXT , logText );
282281 }
283282 }
283+
284+ @ Override
285+ protected void onDestroy () {
286+ super .onDestroy ();
287+ unbinder .unbind ();
288+ }
284289}
0 commit comments