Some fixes
This commit is contained in:
parent
4d61600ed2
commit
287a188361
|
@ -2340,7 +2340,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ExcelToSQLite excelToSQLite = new ExcelToSQLite(getApplicationContext(), DB_NAME, true);
|
ExcelToSQLite excelToSQLite = new ExcelToSQLite(getApplicationContext(), DB_NAME, true);
|
||||||
String filename = SettingsFragment.getPath(getApplicationContext(), data.getData());
|
String filename = Helper.getFilePathFromURI(getApplicationContext(), data.getData());
|
||||||
assert filename != null;
|
assert filename != null;
|
||||||
excelToSQLite.importFromFile(filename, new ExcelToSQLite.ImportListener() {
|
excelToSQLite.importFromFile(filename, new ExcelToSQLite.ImportListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -822,7 +822,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ExcelToSQLite excelToSQLite = new ExcelToSQLite(getApplicationContext(), DB_NAME, true);
|
ExcelToSQLite excelToSQLite = new ExcelToSQLite(getApplicationContext(), DB_NAME, true);
|
||||||
String filename = SettingsFragment.getPath(getApplicationContext(), data.getData());
|
String filename = Helper.getFilePathFromURI(getApplicationContext(), data.getData());
|
||||||
assert filename != null;
|
assert filename != null;
|
||||||
excelToSQLite.importFromFile(filename, new ExcelToSQLite.ImportListener() {
|
excelToSQLite.importFromFile(filename, new ExcelToSQLite.ImportListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -76,6 +76,7 @@ import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.style.ClickableSpan;
|
import android.text.style.ClickableSpan;
|
||||||
import android.text.style.URLSpan;
|
import android.text.style.URLSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
@ -180,6 +181,7 @@ import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
|
||||||
import static android.content.Context.DOWNLOAD_SERVICE;
|
import static android.content.Context.DOWNLOAD_SERVICE;
|
||||||
|
import static com.koushikdutta.async.util.StreamUtility.copyStream;
|
||||||
import static fr.gouv.etalab.mastodon.activities.BaseMainActivity.filters;
|
import static fr.gouv.etalab.mastodon.activities.BaseMainActivity.filters;
|
||||||
|
|
||||||
|
|
||||||
|
@ -560,8 +562,10 @@ public class Helper {
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity));
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity));
|
||||||
Account account = new AccountDAO(activity, db).getUniqAccount(userId, instance);
|
Account account = new AccountDAO(activity, db).getUniqAccount(userId, instance);
|
||||||
account.setToken("null");
|
if( account != null) {
|
||||||
new AccountDAO(activity, db).updateAccount(account);
|
account.setToken("null");
|
||||||
|
new AccountDAO(activity, db).updateAccount(account);
|
||||||
|
}
|
||||||
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
|
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
if( newAccount == null){
|
if( newAccount == null){
|
||||||
|
@ -3687,4 +3691,41 @@ public class Helper {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String getFilePathFromURI(Context context, Uri contentUri) {
|
||||||
|
//copy file and send new file path
|
||||||
|
String fileName = getFileName(contentUri);
|
||||||
|
if (!TextUtils.isEmpty(fileName)) {
|
||||||
|
File copyFile = new File(context.getCacheDir() + File.separator + fileName);
|
||||||
|
copy(context, contentUri, copyFile);
|
||||||
|
return copyFile.getAbsolutePath();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileName(Uri uri) {
|
||||||
|
if (uri == null) return null;
|
||||||
|
String fileName = null;
|
||||||
|
String path = uri.getPath();
|
||||||
|
int cut = path.lastIndexOf('/');
|
||||||
|
if (cut != -1) {
|
||||||
|
fileName = path.substring(cut + 1);
|
||||||
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copy(Context context, Uri srcUri, File dstFile) {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
|
||||||
|
if (inputStream == null) return;
|
||||||
|
OutputStream outputStream = new FileOutputStream(dstFile);
|
||||||
|
copyStream(inputStream, outputStream);
|
||||||
|
inputStream.close();
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
android:title="@string/custom_tabs"
|
android:title="@string/custom_tabs"
|
||||||
app:actionViewClass="android.widget.CheckBox"
|
app:actionViewClass="android.widget.CheckBox"
|
||||||
android:checkable="true"/>
|
android:checkable="true"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_import_data"
|
||||||
|
android:title="@string/import_data"
|
||||||
|
app:showAsAction="never" />
|
||||||
<item android:id="@+id/action_provider"
|
<item android:id="@+id/action_provider"
|
||||||
android:title="@string/set_security_provider"
|
android:title="@string/set_security_provider"
|
||||||
app:actionViewClass="android.widget.CheckBox"
|
app:actionViewClass="android.widget.CheckBox"
|
||||||
|
|
Loading…
Reference in New Issue