Skip to content

Commit

Permalink
Merge pull request #25 from TheAndroidMaster/develop
Browse files Browse the repository at this point in the history
Version 0.0.6
  • Loading branch information
fennifith authored May 7, 2018
2 parents 4dce43f + 11411b9 commit 62d380e
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This is just sample data. It is not real. Though Jahir is lazy, so that part is
The Gradle dependency is available through jCenter, which is used by default in Android Studio. To add the dependency to your project, copy this line into the dependencies section of your app's build.gradle file.

```gradle
compile 'me.jfenn:attribouter:0.0.5'
compile 'me.jfenn:attribouter:0.0.6'
```

#### Starting an Activity
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

compile project(':attribouter')
implementation project(':attribouter')
}
6 changes: 3 additions & 3 deletions attribouter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'me.jfenn'
PUBLISH_ARTIFACT_ID = 'attribouter'
PUBLISH_VERSION = '0.0.5'
PUBLISH_VERSION = '0.0.6'
}

android {
Expand All @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 5
versionName "0.0.5"
versionCode 6
versionName "0.0.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonSyntaxException;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -63,7 +65,12 @@ private void init(String json) {
* @param json the json string
*/
protected void initJson(Gson gson, String json) {
gson.fromJson(json, getClass());
try {
gson.fromJson(json, getClass());
} catch (JsonSyntaxException e) {
e.printStackTrace();
Log.e("Attribouter", "Error parsing JSON from " + url);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public ViewHolder getViewHolder(View v) {
}

@Override
public void bind(Context context, ViewHolder viewHolder) {
public void bind(final Context context, ViewHolder viewHolder) {
ApplicationInfo info = context.getApplicationInfo();
ResourceUtils.setImage(context, icon, info.icon, viewHolder.appIconView);
viewHolder.nameTextView.setText(info.labelRes);
Expand All @@ -127,7 +127,7 @@ public void bind(Context context, ViewHolder viewHolder) {
} else viewHolder.descriptionTextView.setVisibility(View.GONE);

if (links.size() > 0) {
Collections.sort(links);
Collections.sort(links, new LinkInfoData.Comparator(context));

List<InfoData> linksList = new ArrayList<>();
for (LinkInfoData link : links) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public ContributorsInfoData(XmlResourceParser parser) throws XmlPullParserExcept
if (!contributors.contains(contributor))
contributors.add(contributor);
else contributors.get(contributors.indexOf(contributor)).merge(contributor);

if (contributor.login != null && !contributor.hasEverything())
addRequest(new UserData(contributor.login));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public LicenseInfoData(@Nullable String repo, @Nullable String title, @Nullable
else token = title;

links = new ArrayList<>();
if (websiteUrl != null)
if (websiteUrl != null && !websiteUrl.isEmpty())
links.add(new WebsiteLinkInfoData(websiteUrl, 2));
if (repo != null)
links.add(new GitHubLinkInfoData(repo, 1));
Expand Down Expand Up @@ -254,7 +254,7 @@ public void bind(Context context, ViewHolder viewHolder) {
} else viewHolder.licenseView.setVisibility(View.GONE);

if (links.size() > 0) {
Collections.sort(links);
Collections.sort(links, new LinkInfoData.Comparator(context));

List<InfoData> linksList = new ArrayList<>();
for (LinkInfoData link : links) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,6 @@ public ViewHolder getViewHolder(View v) {

@Override
public void bind(Context context, ViewHolder viewHolder) {
if (overflow == 0) {
viewHolder.titleView.setVisibility(View.GONE);
viewHolder.recycler.setVisibility(View.GONE);
viewHolder.expand.setVisibility(View.GONE);

viewHolder.overflow.setVisibility(View.VISIBLE);
viewHolder.overflow.setText(String.format(context.getString(R.string.title_attribouter_view_overflow), translatorsTitle));

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OverflowDialog(v.getContext(), translatorsTitle, sortedTranslators).show();
}
});
return;
} else {
viewHolder.titleView.setVisibility(View.VISIBLE);
viewHolder.recycler.setVisibility(View.VISIBLE);
viewHolder.expand.setVisibility(View.VISIBLE);
viewHolder.overflow.setVisibility(View.GONE);
viewHolder.itemView.setOnClickListener(null);
}

if (translatorsTitle != null)
viewHolder.titleView.setText(ResourceUtils.getString(context, translatorsTitle));

int remaining = overflow;
List<InfoData> sortedList = new ArrayList<>();
sortedTranslators = new ArrayList<>();
Expand Down Expand Up @@ -167,6 +141,31 @@ public void onClick(View v) {
}
}

if (overflow == 0) {
viewHolder.titleView.setVisibility(View.GONE);
viewHolder.recycler.setVisibility(View.GONE);
viewHolder.expand.setVisibility(View.GONE);

viewHolder.overflow.setVisibility(View.VISIBLE);
viewHolder.overflow.setText(String.format(context.getString(R.string.title_attribouter_view_overflow), ResourceUtils.getString(context, translatorsTitle)));

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new OverflowDialog(v.getContext(), translatorsTitle, sortedTranslators).show();
}
});
return;
} else {
viewHolder.titleView.setVisibility(View.VISIBLE);
viewHolder.recycler.setVisibility(View.VISIBLE);
viewHolder.expand.setVisibility(View.VISIBLE);
viewHolder.overflow.setVisibility(View.GONE);
viewHolder.itemView.setOnClickListener(null);
}

if (translatorsTitle != null)
viewHolder.titleView.setText(ResourceUtils.getString(context, translatorsTitle));

viewHolder.recycler.setLayoutManager(new LinearLayoutManager(context));
viewHolder.recycler.setAdapter(new InfoAdapter(sortedList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import me.jfenn.attribouter.utils.ResourceUtils;
import me.jfenn.attribouter.utils.UrlClickListener;

public class LinkInfoData extends InfoData<LinkInfoData.ViewHolder> implements Comparable<LinkInfoData> {
public class LinkInfoData extends InfoData<LinkInfoData.ViewHolder> {

@Nullable
private String id;
Expand Down Expand Up @@ -131,9 +131,10 @@ public void bind(Context context, ViewHolder viewHolder) {
viewHolder.itemView.setOnClickListener(getListener(context));
}

@Override
public int compareTo(@NonNull LinkInfoData o) {
int comparison = name != null && o.name != null ? name.compareTo(o.name) : 0;
public int compareTo(Context context, @NonNull LinkInfoData o) {
String name = ResourceUtils.getString(context, this.name);
String oname = ResourceUtils.getString(context, o.name);
int comparison = name != null && oname != null ? name.compareTo(oname) : 0;
return ((o.priority - priority) * 2) + (comparison / Math.abs(comparison));
}

Expand All @@ -149,4 +150,18 @@ public static class ViewHolder extends InfoData.ViewHolder {
}
}

public static class Comparator implements java.util.Comparator<LinkInfoData> {

private Context context;

public Comparator(Context context) {
this.context = context;
}

@Override
public int compare(LinkInfoData o1, LinkInfoData o2) {
return o1.compareTo(context, o2);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {

bioView.setText(ResourceUtils.getString(getContext(), contributor.bio));
if (contributor.links.size() > 0) {
Collections.sort(contributor.links);
Collections.sort(contributor.links, new LinkInfoData.Comparator(getContext()));

List<InfoData> linksList = new ArrayList<>();
for (LinkInfoData link : contributor.links) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-rc01'
classpath 'com.android.tools.build:gradle:3.1.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 62d380e

Please sign in to comment.