Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and a feature addition #266

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ repositories {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.12'

// compile "com.android.support:support-annotations:${ANDROID_SUPPORT_VERSION}"

implementation "com.android.support:support-v4:${ANDROID_SUPPORT_VERSION}"
// compile "com.android.support:support-v13:${ANDROID_SUPPORT_VERSION}"
implementation "com.android.support:support-v13:${ANDROID_SUPPORT_VERSION}"
implementation "com.android.support:appcompat-v7:${ANDROID_SUPPORT_VERSION}"
implementation "com.android.support:recyclerview-v7:${ANDROID_SUPPORT_VERSION}"
implementation "com.android.support:design:${ANDROID_SUPPORT_VERSION}"
Expand Down Expand Up @@ -172,4 +172,4 @@ dependencies {
implementation "com.timehop.stickyheadersrecyclerview:library:${STICKY_HEAD_VERSION}"

implementation "org.jsoup:jsoup:${JSOUP_VERSION}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Presenter extends IBaseContract.Presenter<ISearchContract.View>{
SearchModel getSortModel(int page, int sortId);
@NonNull ArrayList<String> getSearchRecordList();
void addSearchRecord(@NonNull String record);
void removeSearchRecord(@NonNull String record);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

Expand All @@ -24,7 +25,8 @@
public class SearchPresenter extends BasePresenter<ISearchContract.View>
implements ISearchContract.Presenter {

@AutoAccess ArrayList<SearchModel> searchModels;
@AutoAccess
ArrayList<SearchModel> searchModels;

@Inject
public SearchPresenter(DaoSession daoSession) {
Expand Down Expand Up @@ -78,27 +80,40 @@ public ArrayList<String> getSearchRecordList() {

@Override
public void addSearchRecord(@NonNull String record) {
if(record.contains("$")){
if (record.contains("$")) {
return;
}
int MAX_SEARCH_RECORD_SIZE = 30;
ArrayList<String> recordList = getSearchRecordList();
if(recordList.contains(record)){
if (recordList.contains(record)) {
recordList.remove(record);
}
if(recordList.size() >= MAX_SEARCH_RECORD_SIZE){
if (recordList.size() >= MAX_SEARCH_RECORD_SIZE) {
recordList.remove(recordList.size() - 1);
}
recordList.add(0, record);
StringBuilder recordStr = new StringBuilder("");
String lastRecord = recordList.get(recordList.size() - 1);
for(String str : recordList){
for (String str : recordList) {
recordStr.append(str);
if(!str.equals(lastRecord)){
if (!str.equals(lastRecord)) {
recordStr.append("$$");
}
}
PrefUtils.set(PrefUtils.SEARCH_RECORDS, recordStr.toString());
}

@Override
public void removeSearchRecord(@NonNull String record) {
List<String> recordsList = getSearchRecordList();
recordsList.remove(record);
StringBuilder builder = new StringBuilder();
for (String str : recordsList) {
builder.append(str);
if (!str.equals(recordsList.get(recordsList.size() > 0 ? recordsList.size() - 1 : 0))) {
builder.append("$$");
}
}
PrefUtils.set(PrefUtils.SEARCH_RECORDS, builder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -168,11 +169,18 @@ protected void initView(Bundle savedInstanceState) {
}
navViewStart.setCheckedItem(selectedPage);

ImageView avatar = navViewStart.getHeaderView(0).findViewById(R.id.avatar);
TextView name = navViewStart.getHeaderView(0).findViewById(R.id.name);
TextView mail = navViewStart.getHeaderView(0).findViewById(R.id.mail);
final View navHeader = navViewStart.getHeaderView(0);
ViewCompat.setOnApplyWindowInsetsListener(navHeader, (v, insets) -> {
navHeader.setPadding(navHeader.getPaddingLeft(), insets.getSystemWindowInsetTop(),
navHeader.getPaddingRight(), navHeader.getPaddingBottom());
return insets;
});

ImageView avatar = navHeader.findViewById(R.id.avatar);
TextView name = navHeader.findViewById(R.id.name);
TextView mail = navHeader.findViewById(R.id.mail);

toggleAccountBn = navViewStart.getHeaderView(0).findViewById(R.id.toggle_account_bn);
toggleAccountBn = navHeader.findViewById(R.id.toggle_account_bn);
toggleAccountBn.setOnClickListener(v -> {
toggleAccountLay();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
Expand Down Expand Up @@ -129,6 +131,15 @@ protected void initView(Bundle savedInstanceState) {
setToolbarBackEnable();
setToolbarTitle(mPresenter.getLoginId());
setUserAvatar();
if (toolbar != null) {
ViewCompat.setOnApplyWindowInsetsListener(toolbar, (v, insets) -> {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)
toolbar.getLayoutParams();
params.topMargin = insets.getSystemWindowInsetTop();
toolbar.setLayoutParams(params);
return insets;
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SearchView;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import com.thirtydegreesray.dataautoaccess.annotation.AutoAccess;
Expand All @@ -29,6 +29,7 @@
import com.thirtydegreesray.openhub.mvp.model.SearchModel;
import com.thirtydegreesray.openhub.mvp.presenter.SearchPresenter;
import com.thirtydegreesray.openhub.ui.activity.base.PagerActivity;
import com.thirtydegreesray.openhub.ui.adapter.SearchAutoCompleteAdapter;
import com.thirtydegreesray.openhub.ui.adapter.base.FragmentPagerModel;
import com.thirtydegreesray.openhub.ui.fragment.RepositoriesFragment;
import com.thirtydegreesray.openhub.ui.fragment.UserListFragment;
Expand Down Expand Up @@ -109,15 +110,33 @@ public boolean onCreateOptionsMenu(Menu menu) {
}
MenuItemCompat.setOnActionExpandListener(searchItem, this);

SearchAutoCompleteAdapter.OnSearchItemLongClick searchItemLongClickListener = (adapter, item) -> {
if (item != null) {
new AlertDialog.Builder(this)
.setCancelable(false)
.setMessage(String.format("Remove %s?", item))
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
mPresenter.removeSearchRecord(item);
adapter.clear();
adapter.addAll(mPresenter.getSearchRecordList());
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
.create()
.show();
}
};

AutoCompleteTextView autoCompleteTextView = searchView
.findViewById(android.support.v7.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);
autoCompleteTextView.setAdapter(new ArrayAdapter<>(this,
R.layout.layout_item_simple_list, mPresenter.getSearchRecordList()));
autoCompleteTextView.setAdapter(new SearchAutoCompleteAdapter(
this,
R.layout.layout_item_simple_list,
mPresenter.getSearchRecordList(),
searchItemLongClickListener,
this::onQueryTextSubmit)
);
autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity())));
autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
onQueryTextSubmit(parent.getAdapter().getItem(position).toString());
});

return super.onCreateOptionsMenu(menu);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.thirtydegreesray.openhub.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import java.util.List;

public class SearchAutoCompleteAdapter extends ArrayAdapter<String> {

private OnSearchItemClick mClickListener;
private OnSearchItemLongClick mLongClickListener;

public SearchAutoCompleteAdapter(@NonNull Context context, int resource,
@NonNull List<String> objects, OnSearchItemLongClick longClickListener,
OnSearchItemClick clickListener) {
super(context, resource, objects);
this.mClickListener = clickListener;
this.mLongClickListener = longClickListener;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setOnClickListener((v) -> mClickListener.onClick(getItem(position)));
view.setOnLongClickListener((v) -> {
mLongClickListener.onLongClick(this, getItem(position));
return true;
});
return view;
}

public interface OnSearchItemClick {
void onClick(@Nullable String item);
}

public interface OnSearchItemLongClick {
void onLongClick(SearchAutoCompleteAdapter adapter, @Nullable String item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.thirtydegreesray.openhub.ui.activity.ReleaseInfoActivity;
import com.thirtydegreesray.openhub.ui.activity.ReleasesActivity;
import com.thirtydegreesray.openhub.ui.activity.RepositoryActivity;
import com.thirtydegreesray.openhub.ui.activity.SplashActivity;
import com.thirtydegreesray.openhub.ui.activity.ViewerActivity;

import java.util.ArrayList;
Expand Down Expand Up @@ -180,7 +181,9 @@ public static void launchUrl(@NonNull Context context, @NonNull Uri uri){
repoName = gitHubName.getRepoName();
}

if(GitHubHelper.isUserUrl(url)){
if (GitHubHelper.isHomeUrl(url)) {
context.startActivity(new Intent(context, SplashActivity.class));
} else if(GitHubHelper.isUserUrl(url)){
ProfileActivity.show((Activity) context, userName);
} else if(GitHubHelper.isRepoUrl(url)){
RepositoryActivity.show(context, userName, repoName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class GitHubHelper {

public static final Pattern REPO_FULL_NAME_PATTERN =
Pattern.compile("([a-z]|[A-Z]|\\d|-)*/([a-z]|[A-Z]|\\d|-|\\.|_)*");
private static final Pattern HOME_PATTERN = Pattern.compile(GITHUB_BASE_URL_PATTERN_STR + "/");
private static final Pattern USER_PATTERN = Pattern.compile(GITHUB_BASE_URL_PATTERN_STR
+ "/([a-z]|[A-Z]|\\d|-)*(/)?");
private static final Pattern REPO_PATTERN = Pattern.compile(GITHUB_BASE_URL_PATTERN_STR
Expand Down Expand Up @@ -89,6 +90,10 @@ public static String getExtension(@Nullable String name) {
return MimeTypeMap.getFileExtensionFromUrl(name);
}

public static boolean isHomeUrl(@NonNull String url) {
return HOME_PATTERN.matcher(url).matches();
}

public static boolean isUserUrl(@NonNull String url){
return USER_PATTERN.matcher(url).matches();
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_issue_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
app:collapsedTitleGravity="start"
app:expandedTitleGravity="top"
app:expandedTitleMarginStart="96dp"
app:expandedTitleMarginTop="60dp"
app:expandedTitleMarginTop="56dp"
app:expandedTitleTextAppearance="@style/Toolbar.Expand.TitleText"
android:paddingTop="0dp"
android:paddingBottom="@dimen/spacing_normal">
Expand All @@ -37,7 +37,7 @@
android:layout_gravity="start|top"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/spacing_normal"
android:layout_marginTop="86dp">
android:paddingTop="?attr/actionBarSize">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_avatar"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
app:collapsedTitleGravity="start"
app:expandedTitleGravity="top"
app:expandedTitleMarginStart="96dp"
app:expandedTitleMarginTop="60dp"
app:expandedTitleMarginTop="56dp"
app:expandedTitleTextAppearance="@style/Toolbar.Expand.TitleText"
android:paddingTop="0dp">

Expand All @@ -51,11 +51,11 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|top"
android:layout_gravity="start"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/spacing_normal"
android:paddingBottom="@dimen/spacing_normal"
android:layout_marginTop="86dp">
android:paddingTop="?attr/actionBarSize">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_avatar"
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/activity_repository.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
app:collapsedTitleGravity="start"
app:expandedTitleGravity="top"
app:expandedTitleMarginStart="@dimen/spacing_x_large"
app:expandedTitleMarginTop="60dp"
app:expandedTitleMarginTop="56dp"
app:expandedTitleTextAppearance="@style/Toolbar.Expand.TitleText"
android:paddingTop="0dp">

Expand All @@ -49,13 +49,14 @@
android:fitsSystemWindows="true"/>

<RelativeLayout
android:id="@+id/repo_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|top"
android:layout_gravity="start"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/spacing_normal"
android:paddingBottom="@dimen/spacing_normal"
android:layout_marginTop="86dp">
android:paddingTop="?attr/actionBarSize">

<TextView
android:id="@+id/desc"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/nav_header_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:layout_height="wrap_content"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
Expand Down
Loading