Many improvements

- Use linearadapter for syndicate-to
- Fix problem when finding url in text
- Rewrite WebSignin in Kotlin
- Cleanup bookmark interface
This commit is contained in:
Peter Stuifzand 2018-04-11 00:22:59 +02:00
parent bdda82b6ae
commit 81b095667d
33 changed files with 439 additions and 260 deletions

View File

@ -1,4 +1,5 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android { android {
compileSdkVersion 26 compileSdkVersion 26
@ -43,7 +44,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.9.1' implementation 'com.squareup.okhttp3:okhttp:3.9.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.1'; testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.1';
testImplementation "org.robolectric:robolectric:3.7.1" testImplementation "org.robolectric:robolectric:3.7.1"
apply plugin: 'kotlin-android-extensions'
// Logging // Logging
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
// ViewModel and LiveData // ViewModel and LiveData
@ -58,5 +59,11 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:support-annotations:22.2.0' implementation 'com.android.support:support-annotations:27.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "io.reactivex.rxjava2:rxjava:2.1.12"
}
repositories {
mavenCentral()
} }

View File

@ -22,7 +22,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_logo_round" android:roundIcon="@mipmap/ic_logo_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"

View File

@ -10,6 +10,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -21,7 +22,6 @@ import android.widget.Toast;
import eu.stuifzand.micropub.client.Client; import eu.stuifzand.micropub.client.Client;
import eu.stuifzand.micropub.client.Post; import eu.stuifzand.micropub.client.Post;
import eu.stuifzand.micropub.databinding.ActivityBookmarkBinding; import eu.stuifzand.micropub.databinding.ActivityBookmarkBinding;
import eu.stuifzand.micropub.databinding.ContentBookmarkBinding;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
public class BookmarkActivity extends AppCompatActivity { public class BookmarkActivity extends AppCompatActivity {
@ -36,14 +36,39 @@ public class BookmarkActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActivityBookmarkBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_bookmark);
postModel = ViewModelProviders.of(BookmarkActivity.this).get(PostViewModel.class);
client = ViewModelProviders.of(BookmarkActivity.this).get(Client.class);
binding.setViewModel(postModel);
binding.setClient(client);
// contentBinding.setViewModel(postModel);
// contentBinding.setClient(client);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
if (intent != null) {
Log.i("micropub", intent.toString());
String urlOrNote = intent.getStringExtra(Intent.EXTRA_TEXT);
if (urlOrNote != null) {
HttpUrl url = HttpUrl.parse(urlOrNote);
if (url != null) {
postModel.bookmarkOf.set(urlOrNote);
} else {
postModel.findBookmarkOf(urlOrNote);
}
}
}
accountManager = AccountManager.get(this); accountManager = AccountManager.get(this);
AccountManager am = AccountManager.get(this); AccountManager am = AccountManager.get(this);
Bundle options = new Bundle(); Bundle options = new Bundle();
postModel = ViewModelProviders.of(BookmarkActivity.this).get(PostViewModel.class);
client = ViewModelProviders.of(BookmarkActivity.this).get(Client.class);
TokenReady callback = (accountType, accountName, token) -> { TokenReady callback = (accountType, accountName, token) -> {
Account[] accounts = accountManager.getAccountsByType(accountType); Account[] accounts = accountManager.getAccountsByType(accountType);
if (accounts.length == 0) if (accounts.length == 0)
@ -73,14 +98,6 @@ public class BookmarkActivity extends AppCompatActivity {
Snackbar.make(coordinator, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); Snackbar.make(coordinator, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} }
}); });
client.getMediaResponse().observe(BookmarkActivity.this, response -> {
Log.i("micropub", "media response received " + response.isSuccess());
if (response.isSuccess()) {
postModel.setPhoto(response.getUrl());
Toast.makeText(BookmarkActivity.this, "Photo upload succesful, photo url filled", Toast.LENGTH_SHORT).show();
}
});
}; };
AuthError onError = (msg) -> { AuthError onError = (msg) -> {
@ -100,30 +117,6 @@ public class BookmarkActivity extends AppCompatActivity {
new OnTokenAcquired(this, callback, onError), new OnTokenAcquired(this, callback, onError),
null null
); );
// setContentView(R.layout.activity_main);
ActivityBookmarkBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_bookmark);
ContentBookmarkBinding contentBinding = DataBindingUtil.setContentView(this, R.layout.content_bookmark);
binding.setViewModel(postModel);
binding.setClient(client);
contentBinding.setViewModel(postModel);
contentBinding.setClient(client);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Intent intent = getIntent();
if (intent != null) {
Log.i("micropub", intent.toString());
String urlOrNote = intent.getStringExtra(Intent.EXTRA_TEXT);
if (urlOrNote != null) {
HttpUrl url = HttpUrl.parse(urlOrNote);
if (url != null) {
postModel.bookmarkOf.set(urlOrNote);
} else {
postModel.findBookmarkOf(urlOrNote);
}
}
}
} }
@Override @Override

View File

@ -0,0 +1,109 @@
package eu.stuifzand.micropub;
import android.content.Context;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import java.io.PrintStream;
import java.util.Formatter;
import eu.stuifzand.micropub.client.Syndication;
import eu.stuifzand.micropub.databinding.ListItemBinding;
public class LinearAdapter extends ObservableList.OnListChangedCallback<ObservableArrayList<Syndication>> {
private final LayoutInflater inflater;
private final Handler uiHandler;
private LinearLayout view;
public LinearAdapter(LinearLayout l) {
view = l;
inflater = (LayoutInflater) view.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
uiHandler = new Handler(Looper.getMainLooper());
}
@Override
public void onChanged(ObservableArrayList<Syndication> syndications) {
//updateList(syndications);
Formatter formatter = new Formatter();
formatter.format("onChanged");
Log.i("micropub", formatter.toString());
}
@Override
public void onItemRangeChanged(ObservableArrayList<Syndication> syndications, int f, int n) {
int l = view.getChildCount();
uiHandler.post(() -> {
for (int i = 0; i < n; i++) {
Log.i("micropub", "onItemRangeChanged f=" + f + " n=" + n + " l=" + l);
ListItemBinding binding = null;
if (f + i < l) {
Log.i("micropub", "onItemRangeChanged convert: f+i=" + f + i);
View convertView = view.getChildAt(f + i);
binding = DataBindingUtil.bind(convertView);
} else {
Log.i("micropub", "onItemRangeChanged new: f+i=" + f + i);
binding = DataBindingUtil.inflate(inflater, R.layout.list_item, view, false);
view.addView(binding.getRoot(), f + i);
}
binding.setInfo(syndications.get(f + i));
}
});
}
@Override
public void onItemRangeInserted(ObservableArrayList<Syndication> syndications, int f, int n) {
int l = view.getChildCount();
uiHandler.post(() -> {
Log.i("micropub", "onItemRangeInserted: f=" + f + " n=" + n);
for (int i = 0; i < n; i++) {
Log.i("micropub", "onItemRangeInserted new: f+i=" + f + i);
{
ListItemBinding binding = null;
binding = DataBindingUtil.inflate(inflater, R.layout.list_item, view, false);
binding.setInfo(syndications.get(f + i));
view.addView(binding.getRoot(), f + i >= l ? -1 : f + i);
}
}
});
}
@Override
public void onItemRangeMoved(ObservableArrayList<Syndication> syndications, int f, int f2, int n) {
Formatter formatter = new Formatter();
formatter.format("onItemRangeMoved: %d, %d, %d", f, f2, n);
Log.i("micropub", formatter.toString());
}
@Override
public void onItemRangeRemoved(ObservableArrayList<Syndication> syndications, int f, int n) {
uiHandler.post(() -> {
view.removeViews(f, n);
});
}
protected void updateList(ObservableArrayList<Syndication> list) {
for (Syndication s : list) {
ListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item, view, false);
binding.setInfo(s);
view.addView(binding.getRoot());
}
}
@BindingAdapter("app:multipleItems")
public static void bindList(LinearLayout view, ObservableArrayList<Syndication> list) {
assert list != null;
list.addOnListChangedCallback(new LinearAdapter(view));
}
}

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.databinding.BindingAdapter; import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.databinding.ObservableArrayList; import android.databinding.ObservableArrayList;
import android.provider.ContactsContract;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -42,10 +43,15 @@ public class ListAdapter extends BaseAdapter {
inflater = (LayoutInflater) parent.getContext() inflater = (LayoutInflater) parent.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} }
ListItemBinding binding = null;
if (convertView == null) {
binding = DataBindingUtil.inflate(inflater, R.layout.list_item, parent, false);
} else {
binding = DataBindingUtil.bind(convertView);
}
ListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item, parent, false);
binding.setInfo(list.get(position)); binding.setInfo(list.get(position));
return binding.getRoot(); return binding.getRoot();
} }

View File

@ -3,18 +3,15 @@ package eu.stuifzand.micropub;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.app.Activity; import android.app.Activity;
import android.app.Notification;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.media.session.MediaSession;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.ActionMenuItemView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@ -28,9 +25,9 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import eu.stuifzand.micropub.databinding.ActivityMainBinding;
import eu.stuifzand.micropub.client.Client; import eu.stuifzand.micropub.client.Client;
import eu.stuifzand.micropub.client.Post; import eu.stuifzand.micropub.client.Post;
import eu.stuifzand.micropub.databinding.ActivityMainBinding;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import static eu.stuifzand.micropub.utils.IOUtils.getBytes; import static eu.stuifzand.micropub.utils.IOUtils.getBytes;
@ -45,9 +42,14 @@ public class MainActivity extends AppCompatActivity {
private Client client; private Client client;
private PostViewModel postModel; private PostViewModel postModel;
private ActionMenuItemView actionSend;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
accountManager = AccountManager.get(this); accountManager = AccountManager.get(this);
AccountManager am = AccountManager.get(this); AccountManager am = AccountManager.get(this);
@ -119,7 +121,7 @@ public class MainActivity extends AppCompatActivity {
binding.setViewModel(postModel); binding.setViewModel(postModel);
binding.setClient(client); binding.setClient(client);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
Intent intent = getIntent(); Intent intent = getIntent();

View File

@ -1,5 +1,6 @@
package eu.stuifzand.micropub; package eu.stuifzand.micropub;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel; import android.arch.lifecycle.ViewModel;
import android.databinding.ObservableArrayList; import android.databinding.ObservableArrayList;
import android.databinding.ObservableField; import android.databinding.ObservableField;
@ -16,9 +17,9 @@ import okhttp3.HttpUrl;
public class PostViewModel extends ViewModel { public class PostViewModel extends ViewModel {
private static final Pattern urlPattern = Pattern.compile( private static final Pattern urlPattern = Pattern.compile(
"(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" "(?:^|[\\W])(((ht|f)tp(s?):\\/\\/|www\\.)"
+ "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
+ "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)", + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*))",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
public final ObservableField<String> name = new ObservableField<>(); public final ObservableField<String> name = new ObservableField<>();
@ -71,7 +72,12 @@ public class PostViewModel extends ViewModel {
public void findBookmarkOf(String urlOrNote) { public void findBookmarkOf(String urlOrNote) {
Matcher matcher = urlPattern.matcher(urlOrNote); Matcher matcher = urlPattern.matcher(urlOrNote);
if (matcher.find()) { if (matcher.find()) {
bookmarkOf.set(matcher.group(1)); String url = matcher.group(1);
bookmarkOf.set(url);
String s = urlOrNote.replaceFirst(urlPattern.pattern(), "");
this.name.set(s);
} else {
this.content.set(urlOrNote);
} }
} }

View File

@ -24,5 +24,4 @@ public class AuthenticatorService extends Service {
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return authenticator.getIBinder(); return authenticator.getIBinder();
} }
} }

View File

@ -1,43 +0,0 @@
package eu.stuifzand.micropub.auth;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import eu.stuifzand.micropub.R;
public class WebSigninActivity extends AppCompatActivity {
public static final int AUTHENTICATION_REQUEST = 14;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_signin);
}
public void startWebsignin(View view) {
EditText profileUrl = (EditText) findViewById(R.id.profileUrl);
String url = profileUrl.getText().toString();
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
Intent intent = getIntent();
AccountAuthenticatorResponse parcelable = intent.getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
new WebsigninTask(this, parcelable).execute(url);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTHENTICATION_REQUEST) {
if (resultCode == RESULT_OK) {
finish();
}
}
}
}

View File

@ -0,0 +1,36 @@
package eu.stuifzand.micropub.auth
import android.accounts.AccountAuthenticatorResponse
import android.accounts.AccountManager
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import eu.stuifzand.micropub.R
import kotlinx.android.synthetic.main.activity_web_signin.*
const val AUTHENTICATION_REQUEST = 14;
class WebSigninActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_signin)
}
fun startWebsignin(view : View) {
val url = profileUrl.text.toString();
val me = if (!url.matches(Regex.fromLiteral("^https?://"))) "https://$url" else url
val parcelable = intent.getParcelableExtra<AccountAuthenticatorResponse>(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
WebsigninTask(this, parcelable).execute(me);
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AUTHENTICATION_REQUEST) {
if (resultCode == RESULT_OK) {
finish();
}
}
}
}

View File

@ -25,9 +25,11 @@ import java.util.regex.Pattern;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import static eu.stuifzand.micropub.auth.WebSigninActivityKt.AUTHENTICATION_REQUEST;
public class WebsigninTask extends AsyncTask<String, Void, Bundle> { public class WebsigninTask extends AsyncTask<String, Void, Bundle> {
public static final String ME = "eu.stuifzand.micropub.ME"; static final String ME = "eu.stuifzand.micropub.ME";
protected AccountAuthenticatorResponse response; protected AccountAuthenticatorResponse response;
protected Activity activity; protected Activity activity;
@ -118,6 +120,6 @@ public class WebsigninTask extends AsyncTask<String, Void, Bundle> {
intent.putExtras(bundle); intent.putExtras(bundle);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
this.activity.startActivityForResult(intent, WebSigninActivity.AUTHENTICATION_REQUEST); this.activity.startActivityForResult(intent, AUTHENTICATION_REQUEST);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 B

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
tools:context="eu.stuifzand.micropub.BookmarkActivity">
<data> <data>
<variable <variable
name="viewModel" name="viewModel"
@ -15,8 +14,11 @@
</data> </data>
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
tools:context="eu.stuifzand.micropub.BookmarkActivity"
android:windowSoftInputMode="adjustResize">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -32,14 +34,14 @@
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<include layout="@layout/content_bookmark" /> <include
layout="@layout/content_bookmark"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:client="@{client}"
app:viewModel="@{viewModel}"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:layout_editor_absoluteY="-4dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>
</layout> </layout>

View File

@ -17,7 +17,8 @@
android:id="@+id/coordinator" android:id="@+id/coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="eu.stuifzand.micropub.MainActivity"> tools:context="eu.stuifzand.micropub.MainActivity"
android:windowSoftInputMode="adjustResize">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,13 +36,12 @@
<include <include
layout="@layout/content_main" layout="@layout/content_main"
android:layout_height="607dp"
app:viewModel="@{viewModel}"
app:client="@{client}"
tools:layout_editor_absoluteY="-4dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
app:client="@{client}"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
/> app:viewModel="@{viewModel}"
tools:layout_editor_absoluteY="-4dp" />
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>
</layout> </layout>

View File

@ -14,145 +14,162 @@
type="eu.stuifzand.micropub.client.Client" /> type="eu.stuifzand.micropub.client.Client" />
</data> </data>
<android.support.design.widget.CoordinatorLayout <ScrollView
android:id="@+id/coordinator" android:id="@+id/scrollView_bookmark"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="eu.stuifzand.micropub.BookmarkActivity" tools:context="eu.stuifzand.micropub.BookmarkActivity"
tools:showIn="@layout/activity_bookmark"> tools:showIn="@layout/activity_bookmark">
<android.support.constraint.ConstraintLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<android.support.design.widget.TextInputLayout <android.support.constraint.ConstraintLayout
android:id="@+id/editBookmarkOfTextLayout" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="574dp"
android:layout_height="wrap_content" android:overScrollMode="always"
app:layout_constraintBottom_toTopOf="@+id/contentLayout" android:paddingTop="8dp"
app:layout_constraintEnd_toEndOf="parent" android:scrollbars="vertical">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputLayout
android:id="@+id/editBookmarkOfText" android:id="@+id/editBookmarkOfTextLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Bookmark of" android:layout_marginBottom="8dp"
android:singleLine="true" app:layout_constraintBottom_toTopOf="@+id/editNameLayout"
android:text="@={viewModel.bookmarkOf}" /> app:layout_constraintEnd_toEndOf="parent"
</android.support.design.widget.TextInputLayout> app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside">
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputEditText
android:id="@+id/contentLayout" android:id="@+id/editBookmarkOfText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/content" android:hint="Bookmark of"
app:counterEnabled="true" android:singleLine="true"
app:layout_constraintBottom_toTopOf="@+id/editNameLayout" android:text="@={viewModel.bookmarkOf}" />
app:layout_constraintEnd_toEndOf="parent" </android.support.design.widget.TextInputLayout>
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editBookmarkOfTextLayout">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputLayout
android:id="@+id/content" android:id="@+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="100sp"
android:ems="10"
android:gravity="top"
android:imeOptions="actionNext"
android:inputType="textMultiLine|textCapSentences|textAutoComplete"
android:lines="5"
android:nextFocusForward="@id/editCategory"
android:scrollbars="vertical"
android:text="@={viewModel.content}"
tools:layout_editor_absoluteY="101dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/editNameLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/name"
app:counterEnabled="false"
app:layout_constraintBottom_toTopOf="@+id/listLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/contentLayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="56sp"
android:ems="10"
android:imeOptions="actionNext"
android:inputType="textAutoComplete|textUri"
android:lines="1"
android:maxLines="1"
android:nextFocusForward="@id/content"
android:singleLine="true"
android:text="@={viewModel.name}"
app:layout_constraintTop_toBottomOf="@+id/editInReplyToLayout" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/editCategoryLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/categories"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/listLayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/editCategory"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="10" android:layout_marginBottom="8dp"
android:imeOptions="actionNext" android:hint="@string/content"
android:inputType="text" app:counterEnabled="true"
android:lines="1" app:layout_constraintBottom_toTopOf="@+id/editCategoryLayout"
android:maxLines="1" app:layout_constraintEnd_toEndOf="parent"
android:singleLine="true" app:layout_constraintStart_toStartOf="parent"
android:text="@={viewModel.category}" /> app:layout_constraintTop_toBottomOf="@+id/editNameLayout">
</android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputEditText
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="100sp"
android:ems="10"
android:gravity="top"
android:imeOptions="actionNext"
android:inputType="textMultiLine|textCapSentences|textAutoComplete"
android:lines="5"
android:nextFocusForward="@id/editCategory"
android:scrollbars="vertical"
android:text="@={viewModel.content}"
tools:layout_editor_absoluteY="101dp" />
</android.support.design.widget.TextInputLayout>
<LinearLayout <android.support.design.widget.TextInputLayout
android:id="@+id/listLayout" android:id="@+id/editNameLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="top|fill"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/editCategoryLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editNameLayout">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:text="@string/syndication"
android:textSize="16sp" />
<ListView
android:id="@+id/listSyndication"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="69dp" android:layout_height="wrap_content"
android:isScrollContainer="false" android:layout_marginTop="8dp"
app:list="@{client.syndicates}" /> android:hint="@string/name"
app:counterEnabled="false"
app:layout_constraintBottom_toTopOf="@+id/contentLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editBookmarkOfTextLayout">
</LinearLayout> <android.support.design.widget.TextInputEditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="56sp"
android:ems="10"
android:imeOptions="actionNext"
android:inputType="textAutoComplete|textUri"
android:lines="1"
android:maxLines="1"
android:nextFocusForward="@id/content"
android:singleLine="true"
android:text="@={viewModel.name}"
app:layout_constraintTop_toBottomOf="@+id/editInReplyToLayout" />
</android.support.constraint.ConstraintLayout> </android.support.design.widget.TextInputLayout>
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="@+id/listLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="top|fill"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@+id/editCategoryLayout"
tools:layout_editor_absoluteX="16dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:text="@string/syndication"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/listSyndication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:multipleItems="@{client.syndicates}" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/editCategoryLayout"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:hint="@string/categories"
app:layout_constraintTop_toBottomOf="@+id/contentLayout"
tools:layout_editor_absoluteX="0dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/editCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionNext"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:text="@={viewModel.category}" />
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
</ScrollView>
</layout> </layout>

View File

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable <variable
name="viewModel" name="viewModel"
type="eu.stuifzand.micropub.PostViewModel" /> type="eu.stuifzand.micropub.PostViewModel" />
@ -17,13 +18,7 @@
android:id="@+id/scrollView" android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:windowSoftInputMode="adjustResize"
tools:context="eu.stuifzand.micropub.MainActivity" tools:context="eu.stuifzand.micropub.MainActivity"
tools:showIn="@layout/activity_main"> tools:showIn="@layout/activity_main">
@ -34,7 +29,7 @@
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="617dp"
android:overScrollMode="always" android:overScrollMode="always"
android:paddingTop="8dp" android:paddingTop="8dp"
android:scrollbars="vertical"> android:scrollbars="vertical">
@ -44,8 +39,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/in_reply_to" android:hint="@string/in_reply_to"
app:layout_constraintBottom_toTopOf="@+id/contentLayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
@ -71,19 +67,21 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="@string/content" android:hint="@string/content"
app:counterEnabled="true" app:counterEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/editCategoryLayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editInReplyToLayout"> app:layout_constraintTop_toBottomOf="@+id/editInReplyToLayout">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/content" android:id="@+id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100sp" android:layout_height="wrap_content"
android:ems="10" android:ems="10"
android:gravity="top" android:gravity="top"
android:imeOptions="actionNext" android:imeOptions="actionNext"
android:inputType="textMultiLine|textCapSentences|textAutoComplete" android:inputType="textMultiLine|textCapSentences|textAutoComplete"
android:lines="5" android:lines="10"
android:nextFocusForward="@id/editCategory" android:nextFocusForward="@id/editCategory"
android:scrollbars="vertical" android:scrollbars="vertical"
android:text="@={viewModel.content}" android:text="@={viewModel.content}"
@ -95,9 +93,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/categories" android:hint="@string/categories"
app:layout_constraintBottom_toTopOf="@+id/editPhotoLayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/contentLayout"> app:layout_constraintTop_toBottomOf="@+id/contentLayout">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/editCategory" android:id="@+id/editCategory"
@ -119,9 +119,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="top|fill" android:gravity="top|fill"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/contentLayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editCategoryLayout"> app:layout_constraintTop_toBottomOf="@+id/editPhotoLayout">
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"
@ -148,9 +150,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="Photo url" android:hint="Photo url"
app:layout_constraintBottom_toTopOf="@+id/listLayout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/listLayout"> app:layout_constraintTop_toBottomOf="@+id/editCategoryLayout">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/editPhoto" android:id="@+id/editPhoto"
@ -165,7 +169,14 @@
android:text="@={viewModel.photo}" /> android:text="@={viewModel.photo}" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</layout> </layout>

View File

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable <variable
name="info" name="info"
type="eu.stuifzand.micropub.client.Syndication" /> type="eu.stuifzand.micropub.client.Syndication" />
@ -11,14 +12,13 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<CheckBox <CheckBox
android:id="@+id/enabled" android:id="@+id/enabled"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="@={info.checked}" android:checked="@={info.checked}"
android:text="@{info.name}" android:text="@{info.name}" />
/>
</LinearLayout> </LinearLayout>
</layout> </layout>

View File

@ -19,7 +19,7 @@
<item <item
android:id="@+id/action_send" android:id="@+id/action_send"
android:enabled="true" android:enabled="true"
android:icon="@drawable/ic_send" android:icon="@drawable/ic_send_primary"
android:orderInCategory="10" android:orderInCategory="10"
android:title="@string/action_send" android:title="@string/action_send"
app:showAsAction="always" /> app:showAsAction="always" />

View File

@ -1,7 +1,7 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
@ -13,7 +13,9 @@
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
</style> </style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

View File

@ -0,0 +1,28 @@
package eu.stuifzand.micropub;
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
public class PostViewModelTest {
private static final Pattern urlPattern = Pattern.compile(
"(?:^|[\\W])(((ht|f)tp(s?):\\/\\/|www\\.)"
+ "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
+ "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*))",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
@Test
public void parseUrl() {
String text = "HELLO WORLD: https://medium.com/@abangkis/architecture-components-livedata-and-fusedlocationprovider-de46580d0481 and text after";
String url = "https://medium.com/@abangkis/architecture-components-livedata-and-fusedlocationprovider-de46580d0481";
Matcher matcher = urlPattern.matcher(text);
assertTrue(matcher.find());
String group = matcher.group(1);
assertEquals(url, group);
}
}

View File

@ -1,14 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.2.31'
repositories { repositories {
google() google()
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Sun Feb 18 19:57:52 CET 2018 #Tue Mar 27 07:29:19 CEST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip