Skip to content

Commit

Permalink
Fixed everything and finished application
Browse files Browse the repository at this point in the history
  • Loading branch information
cverver committed Sep 16, 2016
1 parent 898ba63 commit d65a353
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 58 deletions.
28 changes: 0 additions & 28 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,32 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.0.0-alpha1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.0.0-alpha1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.0.0-alpha1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.0.0-alpha1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android SDK 23" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-24.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-24.0.0-alpha1" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.example.module1.app;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class HyperlinkArrayAdapter extends ArrayAdapter<Hyperlink> {
Context context;
int layoutResourceId;
Hyperlink[] hyperlinks;

public HyperlinkArrayAdapter(Context context, int resource) {
super(context, resource);
}

public HyperlinkArrayAdapter(Context context, int resource, int textViewResourceId) {
super(context, resource, textViewResourceId);
}

public HyperlinkArrayAdapter(Context context, int resource, Hyperlink[] objects) {
super(context, resource, objects);
this.layoutResourceId = resource;
this.context = context;
this.hyperlinks = objects;
}

public HyperlinkArrayAdapter(Context context, int resource, int textViewResourceId, Hyperlink[] objects) {
super(context, resource, textViewResourceId, objects);
}

public HyperlinkArrayAdapter(Context context, int resource, List<Hyperlink> objects) {
super(context, resource, objects);
}

public HyperlinkArrayAdapter(Context context, int resource, int textViewResourceId, List<Hyperlink> objects) {
super(context, resource, textViewResourceId, objects);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
HyperlinkHolder holder;

if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);

holder = new HyperlinkHolder();
holder.txtID = (TextView) row.findViewById(R.id.hyperlinkID);
holder.txtDescription = (TextView) row.findViewById(R.id.hyperlinkDescription);
holder.txtURL = (TextView) row.findViewById(R.id.hyperlinkURL);
holder.txtCategory = (TextView) row.findViewById(R.id.hyperlinkCategory);
holder.txtTimestamp = (TextView) row.findViewById(R.id.hyperlinkTimestamp);

row.setTag(holder);
} else {
holder = (HyperlinkHolder) row.getTag();
}

Hyperlink h = hyperlinks[position];
holder.txtID.setText(h.ID.toString());
holder.txtDescription.setText(h.Description);
holder.txtURL.setText(h.URL);
holder.txtCategory.setText(context.getResources().getStringArray(R.array.cats)[h.Category]);
holder.txtTimestamp.setText(h.Timestamp);

return row;
}


static class HyperlinkHolder {
TextView txtID;
TextView txtDescription;
TextView txtURL;
TextView txtCategory;
TextView txtTimestamp;
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/org/example/module1/app/ListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public ListFragment() {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle(getString(R.string.list));
//TODO: stuff
h = mainActivity.onListHyperlinks();

list = (ListView) getView().findViewById(R.id.hyperlinkListView);

list.setAdapter(new HyperlinkArrayAdapter(getActivity(), R.layout.hyperlink, h));
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mainActivity.onOpenHyperlink(((Hyperlink) list.getItemAtPosition(position)));
mainActivity.onOpenHyperlink((Hyperlink) list.getItemAtPosition(position));
}
});
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/org/example/module1/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Patterns;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements MainFragment.Interface, AddFragment.Interface, ModifyFragment.Interface, RemoveFragment.Interface, ListFragment.Interface {
Expand Down Expand Up @@ -80,17 +81,19 @@ public void onListNavigation() {
}

public Boolean onAddHyperlink(Hyperlink h) {
if (!Patterns.WEB_URL.matcher(h.URL).matches() || h.Description.length() == 0) return false;
db = openOrCreateDatabase("Hyperlinks", MODE_PRIVATE, null);
db.execSQL("INSERT INTO Hyperlinks(URL,Description,Category,Timestamp) VALUES(?,?,?,?)", new Object[]{h.URL, h.Description, h.Category, h.Timestamp});
db.execSQL("INSERT INTO Hyperlinks(URL,Description,Category,Timestamp) VALUES(?,?,?,?)", new Object[]{h.URL.startsWith("http://") || h.URL.startsWith("https://") ? h.URL : "http://" + h.URL, h.Description, h.Category, h.Timestamp});
db.close();
return true;
}

public Boolean onModifyHyperlink(Hyperlink h) {
if (!Patterns.WEB_URL.matcher(h.URL).matches() || h.Description.length() == 0) return false;
db = openOrCreateDatabase("Hyperlinks", MODE_PRIVATE, null);
Cursor c = db.query("Hyperlinks", new String[]{"ID"}, "ID = ?", new String[]{h.ID.toString()}, "", "", "");
if (c.getCount() == 1) {
db.execSQL("UPDATE Hyperlinks SET URL = ?, Description = ?, Category = ? WHERE ID = ?", new Object[]{h.URL, h.Description, h.Category, h.ID});
db.execSQL("UPDATE Hyperlinks SET URL = ?, Description = ?, Category = ?, Timestamp = ? WHERE ID = ?", new Object[]{h.URL.startsWith("http://") || h.URL.startsWith("https://") ? h.URL : "http://" + h.URL, h.Description, h.Category, h.Timestamp, h.ID});
c.close();
db.close();
return true;
Expand Down Expand Up @@ -145,15 +148,14 @@ public Hyperlink[] onListHyperlinks() {
Timestamp = c.getString(c.getColumnIndex("Timestamp"));
}};
}
c.close();
db.close();
return h;
}

public void onOpenHyperlink(Hyperlink h) {
//TODO
String url = h.URL;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
i.setData(Uri.parse(h.URL));
startActivity(i);
}
}
22 changes: 9 additions & 13 deletions app/src/main/res/layout/fragment_list.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.example.module1.app.ListFragment" >
<ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView" >
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hyperlinkListView" />
</ScrollView >
</RelativeLayout >
android:fillViewport="true"
tools:context="org.example.module1.app.ListFragment" >
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/hyperlinkListView" />
</ScrollView >
81 changes: 81 additions & 0 deletions app/src/main/res/layout/hyperlink.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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" >
<RelativeLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/description"
android:id="@+id/textViewDescription"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/hyperlinkDescription"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" />
</RelativeLayout >
<RelativeLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="URL"
android:id="@+id/textView3"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/hyperlinkURL"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentEnd="true" />
</RelativeLayout >
<RelativeLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/category"
android:id="@+id/textViewCategory"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/hyperlinkCategory"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" />
</RelativeLayout >
<RelativeLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hyperlinkID"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/hyperlinkTimestamp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" />
</RelativeLayout >
</LinearLayout >
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Fri Sep 16 11:44:51 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip

0 comments on commit d65a353

Please sign in to comment.