Skip to content

Commit

Permalink
get rid of aboutlibraries
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanaev committed Apr 17, 2016
1 parent 1f3f04a commit d0b4bed
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 41 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ dependencies {
compile 'com.android.support:design:22.2.0'
compile 'com.github.junrar:junrar:0.7'
compile 'com.squareup.picasso:picasso:2.5.2'
compile('com.mikepenz:aboutlibraries:5.0.9@aar') { transitive = true }
}
51 changes: 11 additions & 40 deletions app/src/main/java/com/nkanaev/comics/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
package com.nkanaev.comics.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.design.widget.NavigationView;
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener;

import com.nkanaev.comics.fragment.HeaderFragment;
import com.nkanaev.comics.managers.Utils;
import com.squareup.picasso.Picasso;
import com.mikepenz.aboutlibraries.LibsBuilder;
import com.mikepenz.aboutlibraries.entity.Library;
import com.mikepenz.aboutlibraries.ui.LibsFragment;

import android.view.MenuItem;
import com.nkanaev.comics.R;
import com.nkanaev.comics.fragment.AboutFragment;
import com.nkanaev.comics.fragment.BrowserFragment;
import com.nkanaev.comics.fragment.HeaderFragment;
import com.nkanaev.comics.fragment.LibraryFragment;
import com.nkanaev.comics.R;
import com.nkanaev.comics.managers.LocalCoverHandler;

import java.util.*;
import com.nkanaev.comics.managers.Utils;
import com.squareup.picasso.Picasso;


public class MainActivity extends AppCompatActivity implements FragmentManager.OnBackStackChangedListener {
Expand Down Expand Up @@ -158,7 +152,7 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
break;
case R.id.drawer_menu_about:
setTitle(R.string.menu_about);
setFragment(createAboutFragment());
setFragment(new AboutFragment());
break;
}

Expand All @@ -175,29 +169,6 @@ public void onBackStackChanged() {
mDrawerToggle.setDrawerIndicatorEnabled(getSupportFragmentManager().getBackStackEntryCount() == 0);
}

private LibsFragment createAboutFragment() {
final List<String> libraryOrder = Arrays.asList("Picasso", "Junrar", "AboutLibraries");

return new LibsBuilder()
.withAboutIconShown(true)
.withAboutAppName(getString(R.string.app_name))
.withAboutDescription(getString(R.string.app_description))
.withAboutVersionShown(true)
.withAnimations(false)
.withLicenseShown(true)
.withFields(R.string.class.getFields())
.withLibraries("Picasso", "Junrar")
.withLibraryComparator(new Comparator<Library>() {
@Override
public int compare(Library l1, Library l2) {
Integer i1 = libraryOrder.indexOf(l1.getDefinedName());
Integer i2 = libraryOrder.indexOf(l2.getDefinedName());
return i1.compareTo(i2);
}
})
.fragment();
}

@Override
public void onBackPressed() {
if (!popFragment()) {
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/com/nkanaev/comics/fragment/AboutFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.nkanaev.comics.fragment;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nkanaev.comics.R;

public class AboutFragment extends Fragment implements View.OnClickListener {
private class LibraryDescription {
public final String name;
public final String description;
public final String license;
public final String owner;
public final String link;

LibraryDescription(String name, String description, String license, String owner, String link) {
this.name = name;
this.description = description;
this.license = license;
this.owner = owner;
this.link = link;
}
}

private LibraryDescription[] mDescriptions = new LibraryDescription[]{
new LibraryDescription(
"Picasso",
"A powerful image downloading and caching library for Android",
"Apache Version 2.0",
"Square",
"https://github.com/square/picasso"
),
new LibraryDescription(
"Junrar",
"Plain java unrar util",
"Unrar License",
"Edmund Wagner",
"https://github.com/edmund-wagner/junrar"
)
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_about, container, false);

LinearLayout libsLayout = (LinearLayout) view.findViewById(R.id.about_libraries);

((TextView) view.findViewById(R.id.aboutVersion)).setText(getVersionString());

for (int i = 0; i < mDescriptions.length; i++) {
View cardView = inflater.inflate(R.layout.card_deps, libsLayout, false);

((TextView) cardView.findViewById(R.id.libraryName)).setText(mDescriptions[i].name);
((TextView) cardView.findViewById(R.id.libraryCreator)).setText(mDescriptions[i].owner);
((TextView) cardView.findViewById(R.id.libraryDescription)).setText(mDescriptions[i].description);
((TextView) cardView.findViewById(R.id.libraryLicense)).setText(mDescriptions[i].license);

cardView.setTag(mDescriptions[i].link);
cardView.setOnClickListener(this);
libsLayout.addView(cardView);
}

return view;
}

private String getVersionString() {
try {
PackageInfo pi = getActivity()
.getPackageManager()
.getPackageInfo(getActivity().getPackageName(), 0);
return "Version " + pi.versionName + " (" + Integer.toString(pi.versionCode) + ")";
}
catch (PackageManager.NameNotFoundException e) {
return "";
}
}

@Override
public void onClick(View v) {
String link = (String) v.getTag();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
startActivity(browserIntent);
}
}
102 changes: 102 additions & 0 deletions app/src/main/res/layout/card_deps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:foreground="?selectableItemBackground"
android:layoutDirection="ltr">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp">

<TextView
android:id="@+id/libraryName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ellipsize="end"
android:gravity="start"
android:maxLines="1"
android:textSize="@dimen/textSizeLarge_openSource"
android:textStyle="normal"
tools:text="" />

<TextView
android:id="@+id/libraryCreator"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_weight="2"
android:gravity="end"
android:maxLines="2"
android:textSize="@dimen/textSizeSmall_openSource"
android:textColor="#666"
android:textStyle="normal"
tools:text="" />
</LinearLayout>

<View
android:id="@+id/libraryDescriptionDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="#CCC"/>

<TextView
android:id="@+id/libraryDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="20"
android:padding="8dp"
android:textSize="@dimen/textSizeSmall_openSource"
android:textColor="#666"
android:textStyle="normal"
tools:text="">
</TextView>

<View
android:id="@+id/libraryBottomDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="#CCC"/>

<LinearLayout
android:id="@+id/libraryBottomContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp">

<TextView
android:id="@+id/libraryLicense"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:maxLines="1"
android:textSize="@dimen/textSizeSmall_openSource"
android:textColor="#666"
android:textStyle="normal"
tools:text="License" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
77 changes: 77 additions & 0 deletions app/src/main/res/layout/fragment_about.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp">

<ImageView
android:id="@+id/aboutIcon"
android:layout_width="@dimen/aboutImage_openSource"
android:layout_height="@dimen/aboutImage_openSource"
android:layout_gravity="center"
android:src="@drawable/ic_launcher"/>

<TextView
android:id="@+id/aboutName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="center"
android:textSize="@dimen/textSizeLarge_openSource"
android:text="@string/app_name"/>

<TextView
android:id="@+id/aboutVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:gravity="center"
android:textSize="@dimen/textSizeSmall_openSource"
android:textColor="#666"
android:text=""/>

<View
android:id="@+id/aboutDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="#CCC"/>

<TextView
android:id="@+id/aboutDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:padding="8dp"
android:textSize="@dimen/textSizeSmall_openSource"
android:textStyle="normal"
android:textColor="#666"
android:text="@string/app_description"/>
</LinearLayout>

<LinearLayout
android:id="@+id/about_libraries"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
14 changes: 14 additions & 0 deletions app/src/main/res/values/dimen_aboutlibraries.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="card_padding_openSource">12dp</dimen>

<dimen name="aboutImage_openSource">72dp</dimen>

<dimen name="textSizeLarge_openSource">20sp</dimen>
<dimen name="textSizeSmall_openSource">14sp</dimen>


<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

0 comments on commit d0b4bed

Please sign in to comment.