Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ShoppingList/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (localPropertiesFile.exists()) {
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileSdk targetSdkVersion

defaultConfig {
applicationId "org.openintents.shopping"
Expand Down Expand Up @@ -48,8 +48,8 @@ android {

def propertyFile = new File(projectDir, "build-private.properties")
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
if (propertyFile.exists()) {
signingConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -33,9 +32,7 @@
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.provider.OpenableColumns;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.util.Xml.Encoding;
import android.view.LayoutInflater;
Expand All @@ -47,7 +44,6 @@
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
Expand Down Expand Up @@ -85,6 +81,7 @@ public class ConvertCsvBaseActivity extends AppCompatActivity {
protected static final int DIALOG_ID_PERMISSIONS = 4;
protected static final int DIALOG_DISTRIBUTION_START = 100; // MUST BE LAST
protected static final int REQUEST_CODE_PICK_FILE = 1;
protected static final int REQUEST_CODE_NEW_FILE = 2;
private final static String TAG = "ConvertCsvBaseActivity";
// This is the activity's message handler that the worker thread can use to communicate
// with the main thread. This may be null if the activity is paused and could change, so
Expand All @@ -94,8 +91,8 @@ public class ConvertCsvBaseActivity extends AppCompatActivity {
static boolean smHasWorkerThread;
// Max value for the progress bar.
static int smProgressMax;
protected TextView mFilePathView;
protected TextView mFileNameView;
protected String mFilePath;
protected String mFileName;
protected TextView mConvertInfo;
protected Spinner mSpinner;
protected String PREFERENCE_FILENAME;
Expand Down Expand Up @@ -205,24 +202,7 @@ private void switchToMainLayout() {

setPreferencesUsed();

mFilePathView = findViewById(R.id.file_path);
mFileNameView = findViewById(R.id.file_name);

SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(this);
String filepath = pm.getString(PREFERENCE_FILENAME, "");

if (TextUtils.isEmpty(filepath)) {
setFileUriUnknown();
} else {
setFileUri(Uri.parse(filepath));
}


ImageButton buttonFileManager = findViewById(R.id.new_document);
buttonFileManager.setOnClickListener(arg0 -> openFileManagerForNewDocument());

buttonFileManager = findViewById(R.id.open_document);
buttonFileManager.setOnClickListener(arg0 -> openFileManagerForChoosingDocument());

mConvertInfo = findViewById(R.id.convert_info);

Expand Down Expand Up @@ -373,7 +353,7 @@ public void startImport() {
if (importPolicy == IMPORT_POLICY_RESTORE) {
showDialog(DIALOG_ID_WARN_RESTORE_POLICY);
} else {
startImportPostCheck();
openFileManagerForChoosingDocument();
}
}

Expand All @@ -383,7 +363,6 @@ public void startImportPostCheck() {
//getContentResolver().delete(Shopping.Items.CONTENT_URI, null, null);
//getContentResolver().delete(Shopping.Lists.CONTENT_URI, null, null);


String fileName = getFilenameAndSavePreferences();

Log.i(TAG, "Importing..." + fileName);
Expand Down Expand Up @@ -422,7 +401,6 @@ public void run() {

reader.close();
dispatchSuccess(R.string.import_finished);
onImportFinished();

} catch (FileNotFoundException e) {
dispatchError(R.string.error_file_not_found);
Expand Down Expand Up @@ -467,19 +445,23 @@ public int getDocumentSize(Uri uri) {
}

public String getDocumentName(Uri uri) {
Cursor cursor = getContentResolver()
.query(uri, null, null, null, null, null);

String displayName = uri.getLastPathSegment();
String displayName = "";
try {
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
if (cursor != null) {
cursor.close();
Cursor cursor = getContentResolver()
.query(uri, null, null, null, null, null);

displayName = uri.getLastPathSegment();
try {
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
if (cursor != null) {
cursor.close();
}
}
} catch (Exception e) {
}
return displayName;
}
Expand Down Expand Up @@ -531,7 +513,7 @@ public void onImportFinished() {

public void startExport() {
Log.i(TAG, "Exporting...");
doExport();
openFileManagerForNewDocument();
}

public void doExport() {
Expand Down Expand Up @@ -584,7 +566,7 @@ public void doExport(Writer writer) throws IOException {
*/
public String getFilenameAndSavePreferences() {

String fileName = mFilePathView.getText().toString();
String fileName = mFilePath;

SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -721,26 +703,24 @@ private void saveBooleanPreference(String preference, boolean value) {

private void openFileManagerForNewDocument() {

String fileName = mFileNameView.getText().toString();
String filePath = mFilePathView.getText().toString();
if (TextUtils.isEmpty(filePath)) {
fileName = DEFAULT_FILENAME;
}
String fileName = "";
String filePath = DEFAULT_FILENAME;

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/*");
intent.putExtra(Intent.EXTRA_TITLE, fileName);

try {
startActivityForResult(intent, REQUEST_CODE_PICK_FILE);
startActivityForResult(intent, REQUEST_CODE_NEW_FILE);
} catch (ActivityNotFoundException e) {
showDialog(DIALOG_ID_NO_FILE_MANAGER_AVAILABLE);
}
}

private void openFileManagerForChoosingDocument() {

String fileName = mFilePathView.getText().toString();
String fileName = "";

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

Expand Down Expand Up @@ -781,6 +761,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG, "onActivityResult");

switch (requestCode) {
case REQUEST_CODE_NEW_FILE:
if (resultCode == RESULT_OK && data != null) {
Uri documentUri = data.getData();
if (documentUri != null) {
setFileUri(documentUri);
} else {
setFileUriUnknown();
}
doExport();
}
break;
case REQUEST_CODE_PICK_FILE:
if (resultCode == RESULT_OK && data != null) {
Uri documentUri = data.getData();
Expand All @@ -789,19 +780,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
} else {
setFileUriUnknown();
}

startImportPostCheck();
}
break;
}
}

private void setFileUriUnknown() {
mFileNameView.setText(getString(R.string.unknown_document));
mFilePathView.setText("");
mFileName = getString(R.string.unknown_document);
mFilePath = "";
}

private void setFileUri(Uri documentUri) {
mFileNameView.setText(getDocumentName(documentUri));
mFilePathView.setText(documentUri.toString());
mFileName = getDocumentName(documentUri);
mFilePath = documentUri.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ public void doImport(Reader reader) throws IOException,

@Override
public void onImportFinished() {
Intent i = new Intent(Intent.ACTION_VIEW);
Uri uri = ShoppingContract.Lists.CONTENT_URI.buildUpon().appendPath(String.valueOf(getCurrentListId())).build();
i.setData(uri);
startActivity(i);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,6 @@ public boolean onCreateOptionsMenu(Menu menu) {

menu.add(0, MENU_SYNC_WEAR, 0, R.string.sync_wear);

menu.add(0, MENU_CONVERT_CSV, 0, R.string.convert_csv);

// Add distribution menu items last.
mDistribution.onCreateOptionsMenu(menu);

Expand Down
43 changes: 0 additions & 43 deletions ShoppingList/src/main/res/layout/convert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,49 +37,6 @@
android:textAppearance="?android:attr/textAppearanceMedium"
/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<TextView
android:id="@+id/file_path"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:text="@string/default_filename"
android:visibility="gone"
/>

<TextView
android:id="@+id/file_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:text="@string/default_filename"
/>

<ImageButton
android:id="@+id/new_document"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/new_file"
android:src="@drawable/ic_launcher_folder_new_small"/>

<ImageButton
android:id="@+id/open_document"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/choose_file"
android:src="@drawable/ic_launcher_folder_small"/>
</LinearLayout>

<TextView
android:id="@+id/convert_info"
android:layout_width="fill_parent"
Expand Down
2 changes: 1 addition & 1 deletion ShoppingList/src/main/res/values/strings-convertcsv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<string name="convert_csv_shoppinglist">Convert CSV to Shopping list</string>
<string name="convert_all_notes">Convert all notes</string>
<string name="convert_all_shoppinglists">Convert all shopping lists</string>
<string name="convert_list">Convert list \'%s\'</string>
<string name="convert_list">Convert list %s</string>
<string name="file_path">File path</string>
<string name="new_file">New file</string>
<string name="choose_file">Choose file</string>
Expand Down
4 changes: 4 additions & 0 deletions ShoppingListLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.2.2'
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=c9910513d0eed63cd8f5c7fec4cb4a05731144770104a0871234a4edc3ba3cef
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading