Merge branch 'develop' of https://gitlab.com/tom79/mastalab into develop

This commit is contained in:
tom79 2019-02-23 14:25:28 +01:00
commit 4d61600ed2
7 changed files with 180 additions and 58 deletions

View File

@ -93,7 +93,7 @@ dependencies {
implementation 'org.apache.poi:poi:3.16'
implementation 'com.github.mabbas007:TagsEditText:1.0.5'
implementation 'com.jaredrummler:material-spinner:1.3.1'
implementation 'com.github.stom79:SQLite2XL:1.0.5'
implementation 'com.github.stom79:SQLite2XL:1.2'
implementation "com.tonyodev.fetch2:fetch2:2.3.6"
playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion"
}

View File

@ -1437,6 +1437,9 @@ public abstract class BaseMainActivity extends BaseActivity
SQLiteToExcel sqliteToExcel = new SQLiteToExcel(BaseMainActivity.this, DB_NAME);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
final String fileName = "Mastalab_export_"+timeStamp+".xls";
List<String> excludedValues = new ArrayList<>();
excludedValues.add(Sqlite.TABLE_TRACKING_BLOCK);
sqliteToExcel.setExcludeValuesFromTables(excludedValues);
sqliteToExcel.exportAllTables(fileName, new SQLiteToExcel.ExportListener() {
@Override
public void onStart() {
@ -1453,10 +1456,11 @@ public abstract class BaseMainActivity extends BaseActivity
intent.setDataAndType(uri, "application/vnd.ms-excel");
Helper.notify_user(getApplicationContext(), intent, notificationIdTmp, BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher), Helper.NotifType.STORE, getString(R.string.save_over), getString(R.string.download_from, fileName));
Toasty.success(getApplicationContext(), getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
Toasty.success(getApplicationContext(), getString(R.string.data_base_exported),Toast.LENGTH_LONG).show();
}
@Override
public void onError(Exception e) {
e.printStackTrace();
Toasty.error(getApplicationContext(), getString(R.string.data_export_error_simple),Toast.LENGTH_LONG).show();
}
});
@ -2347,10 +2351,7 @@ public abstract class BaseMainActivity extends BaseActivity
@Override
public void onCompleted(String dbName) {
Toasty.success(getApplicationContext(),getString(R.string.data_import_success_simple),Toast.LENGTH_LONG).show();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.finish();
activity.startActivity(changeAccount);
Helper.logoutCurrentUser(BaseMainActivity.this);
}
@Override

View File

@ -14,17 +14,22 @@
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
@ -50,6 +55,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.ajts.androidmads.library.ExcelToSQLite;
import com.elconfidencial.bubbleshowcase.BubbleShowCase;
import com.elconfidencial.bubbleshowcase.BubbleShowCaseBuilder;
import com.elconfidencial.bubbleshowcase.BubbleShowCaseListener;
@ -73,6 +79,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.InstanceNodeInfo;
import fr.gouv.etalab.mastodon.client.GNUAPI;
import fr.gouv.etalab.mastodon.client.HttpsConnection;
import fr.gouv.etalab.mastodon.fragments.SettingsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -81,6 +88,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeMaterialSpinnerColor;
import static fr.gouv.etalab.mastodon.helper.Helper.convertDpToPixel;
import static fr.gouv.etalab.mastodon.sqlite.Sqlite.DB_NAME;
/**
@ -109,6 +117,7 @@ public class LoginActivity extends BaseActivity {
private LinearLayout step_login_credential, step_instance;
private TextView instance_chosen;
private ImageView info_instance;
private final int PICK_IMPORT = 5557;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -774,11 +783,68 @@ public class LoginActivity extends BaseActivity {
editor.putBoolean(Helper.SET_SECURITY_PROVIDER, item.isChecked());
editor.apply();
return false;
}else if(id == R.id.action_import_data){
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (ContextCompat.checkSelfPermission(LoginActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(LoginActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
TootActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return true;
}
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
intent.setType("application/vnd.ms-excel");
String[] mimetypes = {"application/vnd.ms-excel"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMPORT);
}else {
intent.setType("application/vnd.ms-excel");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_import));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
startActivityForResult(chooserIntent, PICK_IMPORT);
}
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMPORT && resultCode == Activity.RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(getApplicationContext(),getString(R.string.toot_select_file_error),Toast.LENGTH_LONG).show();
return;
}
ExcelToSQLite excelToSQLite = new ExcelToSQLite(getApplicationContext(), DB_NAME, true);
String filename = SettingsFragment.getPath(getApplicationContext(), data.getData());
assert filename != null;
excelToSQLite.importFromFile(filename, new ExcelToSQLite.ImportListener() {
@Override
public void onStart() {
Toasty.success(getApplicationContext(),getString(R.string.data_import_start),Toast.LENGTH_LONG).show();
}
@Override
public void onCompleted(String dbName) {
Toasty.success(getApplicationContext(),getString(R.string.data_import_success_simple),Toast.LENGTH_LONG).show();
Helper.logoutCurrentUser(LoginActivity.this);
}
@Override
public void onError(Exception e) {
Toasty.error(getApplicationContext(),getString(R.string.data_import_error_simple),Toast.LENGTH_LONG).show();
}
});
}
}
public static String redirectUserToAuthorizeAndLogin(String clientId, String instance) {
String queryString = Helper.CLIENT_ID + "="+ clientId;
queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB);

View File

@ -1593,6 +1593,11 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
if( itemStore != null)
itemStore.setVisible(false);
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
MenuItem itemContacts = menu.findItem(R.id.action_contacts);
if( itemContacts != null)
itemContacts.setVisible(false);
}
return true;
}

View File

@ -28,6 +28,7 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.client.GNUAPI;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -67,60 +68,108 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
if( this.contextReference.get() == null)
return null;
API api = new API(this.contextReference.get());
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus = null;
APIResponse apiResponse = null;
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
apiResponse = api.getHomeTimelineSinceId(since_id);
}else if( type == RetrieveFeedsAsyncTask.Type.DIRECT)
apiResponse = api.getDirectTimelineSinceId(since_id);
else if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION)
apiResponse = api.getConversationTimelineSinceId(since_id);
else if( type == RetrieveFeedsAsyncTask.Type.LOCAL)
apiResponse = api.getPublicTimelineSinceId(true, since_id);
else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC)
apiResponse = api.getPublicTimelineSinceId(false, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
apiResponse = api.getInstanceTimelineSinceId(remoteInstance, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.TAG) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(remoteInstance);
if( tagTimelines != null && tagTimelines.size() > 0){
TagTimeline tagTimeline = tagTimelines.get(0);
boolean isArt = tagTimeline.isART();
if( isArt)
apiResponse = api.getCustomArtTimelineSinceId(false, remoteInstance, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
else
apiResponse = api.getPublicTimelineTagSinceId(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
}else{
apiResponse = api.getPublicTimelineTag(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
}
}else if (type == RetrieveFeedsAsyncTask.Type.ART)
apiResponse = api.getArtTimelineSinceId( false, since_id, null, null, null);
if (apiResponse != null) {
if( type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
tempStatus = apiResponse.getStatuses();
else{
List<Conversation> conversations = apiResponse.getConversations();
tempStatus = new ArrayList<>();
if( conversations != null && conversations.size() > 0){
for(Conversation conversation: conversations){
fr.gouv.etalab.mastodon.client.Entities.Status status = conversation.getLast_status();
List<String> ppConversation = new ArrayList<>();
for (Account account : conversation.getAccounts())
ppConversation.add(account.getAvatar());
status.setConversationProfilePicture(ppConversation);
status.setConversationId(conversation.getId());
tempStatus.add(status);
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api = new API(this.contextReference.get());
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus = null;
APIResponse apiResponse = null;
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
apiResponse = api.getHomeTimelineSinceId(since_id);
} else if (type == RetrieveFeedsAsyncTask.Type.DIRECT)
apiResponse = api.getDirectTimelineSinceId(since_id);
else if (type == RetrieveFeedsAsyncTask.Type.CONVERSATION)
apiResponse = api.getConversationTimelineSinceId(since_id);
else if (type == RetrieveFeedsAsyncTask.Type.LOCAL)
apiResponse = api.getPublicTimelineSinceId(true, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.PUBLIC)
apiResponse = api.getPublicTimelineSinceId(false, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
apiResponse = api.getInstanceTimelineSinceId(remoteInstance, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.TAG) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(remoteInstance);
if (tagTimelines != null && tagTimelines.size() > 0) {
TagTimeline tagTimeline = tagTimelines.get(0);
boolean isArt = tagTimeline.isART();
if (isArt)
apiResponse = api.getCustomArtTimelineSinceId(false, remoteInstance, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
else
apiResponse = api.getPublicTimelineTagSinceId(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
} else {
apiResponse = api.getPublicTimelineTag(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
}
} else if (type == RetrieveFeedsAsyncTask.Type.ART)
apiResponse = api.getArtTimelineSinceId(false, since_id, null, null, null);
if (apiResponse != null) {
if (type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
tempStatus = apiResponse.getStatuses();
else {
List<Conversation> conversations = apiResponse.getConversations();
tempStatus = new ArrayList<>();
if (conversations != null && conversations.size() > 0) {
for (Conversation conversation : conversations) {
fr.gouv.etalab.mastodon.client.Entities.Status status = conversation.getLast_status();
List<String> ppConversation = new ArrayList<>();
for (Account account : conversation.getAccounts())
ppConversation.add(account.getAvatar());
status.setConversationProfilePicture(ppConversation);
status.setConversationId(conversation.getId());
tempStatus.add(status);
}
}
}
}
if( tempStatus != null)
statuses.addAll(0, tempStatus);
}
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
MainActivity.lastHomeId = statuses.get(0).getId();
if (tempStatus != null)
statuses.addAll(0, tempStatus);
}
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
MainActivity.lastHomeId = statuses.get(0).getId();
}
}else{
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus = null;
APIResponse apiResponse = null;
if (type == RetrieveFeedsAsyncTask.Type.GNU_HOME) {
apiResponse = gnuapi.getHomeTimelineSinceId(since_id);
}else if (type == RetrieveFeedsAsyncTask.Type.GNU_LOCAL)
apiResponse = gnuapi.getPublicTimelineSinceId(true, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.GNU_WHOLE)
apiResponse = gnuapi.getPublicTimelineSinceId(false, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.GNU_TAG) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(remoteInstance);
if (tagTimelines != null && tagTimelines.size() > 0) {
TagTimeline tagTimeline = tagTimelines.get(0);
boolean isArt = tagTimeline.isART();
if (isArt)
apiResponse = gnuapi.getCustomArtTimelineSinceId(false, remoteInstance, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
else
apiResponse = gnuapi.getPublicTimelineTagSinceId(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
} else {
apiResponse = gnuapi.getPublicTimelineTag(remoteInstance, false, since_id, tagTimelines.get(0).getAny(), tagTimelines.get(0).getAll(), tagTimelines.get(0).getNone());
}
}
if (apiResponse != null) {
if (type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
tempStatus = apiResponse.getStatuses();
else {
List<Conversation> conversations = apiResponse.getConversations();
tempStatus = new ArrayList<>();
if (conversations != null && conversations.size() > 0) {
for (Conversation conversation : conversations) {
fr.gouv.etalab.mastodon.client.Entities.Status status = conversation.getLast_status();
List<String> ppConversation = new ArrayList<>();
for (Account account : conversation.getAccounts())
ppConversation.add(account.getAvatar());
status.setConversationProfilePicture(ppConversation);
status.setConversationId(conversation.getId());
tempStatus.add(status);
}
}
}
if (tempStatus != null)
statuses.addAll(0, tempStatus);
}
}
return null;
}

View File

@ -65,7 +65,7 @@ public class Sqlite extends SQLiteOpenHelper {
static final String TABLE_BOOST_SCHEDULE = "BOOST_SCHEDULE";
//Table for blocking tracking domains
static final String TABLE_TRACKING_BLOCK = "TRACKING_BLOCK";
public static final String TABLE_TRACKING_BLOCK = "TRACKING_BLOCK";
static final String COL_USER_ID = "USER_ID";
static final String COL_USERNAME = "USERNAME";

View File

@ -897,6 +897,7 @@
<string name="calls_blocked">http calls blocked by the application</string>
<string name="list_of_blocked_domains">List of blocked calls</string>
<string name="submit">Submit</string>
<string name="data_base_exported">The data base has been exported!</string>
<!-- end languages -->