Progress displayed

This commit is contained in:
jens 2021-09-19 20:16:56 +02:00
parent 11f5f8905f
commit 19e85289d9
2 changed files with 32 additions and 15 deletions

View File

@ -48,6 +48,7 @@ public class MainActivity extends Activity
long messageCount = 0;
enum EnumResult { success, errorReadingMessages, noMessages, errorWritingFile };
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
@ -92,7 +93,7 @@ public class MainActivity extends Activity
}
}
class AsyncTaskExport extends AsyncTask<Uri, Integer, Boolean>
class AsyncTaskExport extends AsyncTask<Uri, Integer, EnumResult>
{
String getExportString()
{
@ -168,7 +169,7 @@ public class MainActivity extends Activity
}
@Override
protected Boolean doInBackground(Uri... uriTree)
protected EnumResult doInBackground(Uri... uriTree)
{
int selectedMessageType;
if(rbRcs.isChecked())
@ -185,10 +186,11 @@ public class MainActivity extends Activity
{
if (Looper.myLooper() == null)
Looper.prepare();
Toast.makeText(MainActivity.this, "Error reading messages. Can\'t export.", Toast.LENGTH_SHORT).show();
}
return false;
Toast.makeText(MainActivity.this, "Error reading messages. Can\'t export.", Toast.LENGTH_SHORT).show();
return EnumResult.noMessages;
}
}
@Override
@ -199,14 +201,25 @@ public class MainActivity extends Activity
}
@Override
protected void onPostExecute(Boolean result)
protected void onPostExecute(EnumResult result)
{
super.onPostExecute(result);
if(result)
switch(result)
{
case success:
tvStatus.setText(String.format(getResources().getString(R.string.exported), String.valueOf(messageCount)));
else
tvStatus.setText(getResources().getString(R.string.errorExporting));
break;
case errorReadingMessages:
tvStatus.setText(getResources().getString(R.string.errorReadingMessages));
break;
case noMessages:
tvStatus.setText(getResources().getString(R.string.noMessages));
break;
case errorWritingFile:
tvStatus.setText(getResources().getString(R.string.errorWritingFile));
break;
}
}
}
@ -220,7 +233,7 @@ public class MainActivity extends Activity
switch (requestCode)
{
case requestCodeExport:
AsyncTask<Uri,Integer,Boolean> exportTask = new AsyncTaskExport();
AsyncTask<Uri,Integer,EnumResult> exportTask = new AsyncTaskExport();
exportTask.execute(data.getData());
break;
case requestCodePermissionRequest:
@ -230,7 +243,7 @@ public class MainActivity extends Activity
}
}
boolean exportFiles(Uri uriTree, int messageType, String content)
EnumResult exportFiles(Uri uriTree, int messageType, String content)
{
String messageTypeString;
if(messageType == typeRCS)
@ -269,17 +282,18 @@ public class MainActivity extends Activity
OutputStream out = getApplicationContext().getContentResolver().openOutputStream(exportFile.getUri());
out.write(content.getBytes());
out.close();
return true;
return EnumResult.success;
}
catch (IOException e)
{
e.printStackTrace();
return EnumResult.errorWritingFile;
}
}
else
return EnumResult.errorWritingFile;
// else
// Toast.makeText(MainActivity.this, getResources().getString(R.string.ConfigurationExportError), Toast.LENGTH_LONG).show();
return false;
}
List<Map<String,String>> readMessages(int messageType)

View File

@ -13,4 +13,7 @@
<string name="exporting">Exporting %1$s messages.</string>
<string name="exported">%1$s messages have been exported.</string>
<string name="errorExporting">An error occured while exporting your messages.</string>
<string name="errorReadingMessages">Error reading messages.</string>
<string name="noMessages">There are no messages of the selected type. Nothing exported.</string>
<string name="errorWritingFile">File could not be written.</string>
</resources>