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

commit #2 #2

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.grace.appproject"
minSdkVersion 17
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
Expand All @@ -16,14 +16,18 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.grace.appproject;
package com.example.grace.appproject.test;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.grace.appproject;
package com.example.grace.appproject.test;

import org.junit.Test;

Expand Down
15 changes: 12 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.grace.appproject">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:icon="@android:drawable/ic_menu_agenda"
android:label="Task Planner"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:label="Task Planner"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PopActivity"
android:theme="@style/AppTheme.CustomTheme">
</activity>
</application>

</manifest>
Binary file added app/src/main/assets/fonts/Roboto-Black.ttf
Binary file not shown.
87 changes: 87 additions & 0 deletions app/src/main/java/com/example/grace/appproject/DbHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.example.grace.appproject;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;

/**
* Created by hosun on 2018-08-26.
*/

public class DbHelper extends SQLiteOpenHelper {

private static final String DB_NAME ="EHDev";
private static final int DB_VER = 5;
public static final String DB_TABLE= "Tasks";
public static final String DB_COLUMN1 = "Task";
public static final String DB_COLUMN2 = "Location";
public static final String DB_COLUMN3 = "Date";
public static final String DB_COLUMN4 = "Time";
public static final String DB_COLUMN5 = "Priority";


public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VER);
}

@Override
public void onCreate(SQLiteDatabase db) {
String query = String.format("CREATE TABLE %s (ID INTEGER PRIMARY KEY AUTOINCREMENT,%s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT);",
DB_TABLE,DB_COLUMN1, DB_COLUMN2, DB_COLUMN3, DB_COLUMN4, DB_COLUMN5);
db.execSQL(query);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query = String.format("DROP TABLE IF EXISTS %s", DB_TABLE);
db.execSQL(query);
onCreate(db);
}

// TODO maybe remove after project
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

public void insertNewTask(String title, String location, String date, String time, String priority){
SQLiteDatabase db= this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DB_COLUMN1, title);
values.put(DB_COLUMN2, location);
values.put(DB_COLUMN3, date);
values.put(DB_COLUMN4, time);
values.put(DB_COLUMN5, priority);
db.insertWithOnConflict(DB_TABLE,null,values,SQLiteDatabase.CONFLICT_REPLACE);
db.close();
}

// TODO - must fix: tasks with same title are all deleted together
public void deleteTask(String task){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(DB_TABLE,DB_COLUMN1 + " = ?",new String[]{task});
db.close();
}

public ArrayList<Task> getTaskList(){
ArrayList<Task> taskList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(DB_TABLE,new String[]{DB_COLUMN1, DB_COLUMN2, DB_COLUMN3, DB_COLUMN4, DB_COLUMN5},null,null,null,null,null);
while(cursor.moveToNext()){
Task t = new Task(cursor.getString(cursor.getColumnIndex(DB_COLUMN1)),
cursor.getString(cursor.getColumnIndex(DB_COLUMN2)),
cursor.getString(cursor.getColumnIndex(DB_COLUMN3)),
cursor.getString(cursor.getColumnIndex(DB_COLUMN4)),
cursor.getString(cursor.getColumnIndex(DB_COLUMN5)));
taskList.add(t);
}
cursor.close();
db.close();
return taskList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package com.example.grace.appproject;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.grace.appproject.model.DayForecast;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;

/**
* Created by hosun on 2018-09-01.
*/

public class ExpandableWeatherAdapter extends BaseExpandableListAdapter {

private Context context;
private ArrayList<DayForecast> dataHeader; // header titles
private HashMap<DayForecast ,ArrayList<DayForecast>> weatherContent;
// child data in format of header title, child title

public ExpandableWeatherAdapter(Context context, ArrayList<DayForecast> listDataHeader, HashMap<DayForecast, ArrayList<DayForecast>> listHashMap) {
this.context = context;
this.dataHeader = listDataHeader;
this.weatherContent = listHashMap;
}

@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {

DayForecast curr = (DayForecast) getChild(groupPosition,childPosition);

if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.weather_content, null);
}

TextView mornName = (TextView) convertView.findViewById(R.id.mornName);
TextView mornMax = (TextView) convertView.findViewById(R.id.mornMax);
TextView mornHumid = (TextView) convertView.findViewById(R.id.mornHumid);
ImageView mornIcon = (ImageView) convertView.findViewById(R.id.mornIcon);


TextView aftName = (TextView) convertView.findViewById(R.id.aftName);
TextView aftMax = (TextView) convertView.findViewById(R.id.aftMax);
TextView aftHumid = (TextView) convertView.findViewById(R.id.aftHumid);
ImageView aftIcon = (ImageView) convertView.findViewById(R.id.aftIcon);


TextView evenName = (TextView) convertView.findViewById(R.id.evenName);
TextView evenMax = (TextView) convertView.findViewById(R.id.evenMax);
TextView evenHumid = (TextView) convertView.findViewById(R.id.evenHumid);
ImageView evenIcon = (ImageView) convertView.findViewById(R.id.evenIcon);


mornName.setText(curr.weather.currentCondition.getMornDescr());
mornMax.setText((int) (curr.forecastTemp.maxMorning - 273.15) + "°C");
mornHumid.setText("%" + (int) curr.weather.currentCondition.getMornHumidity());

aftName.setText(curr.weather.currentCondition.getAftDescr());
aftMax.setText((int) (curr.forecastTemp.maxAfternoon - 273.15) + "°C");
aftHumid.setText("%" + (int) curr.weather.currentCondition.getAftHumidity());

evenName.setText(curr.weather.currentCondition.getEvenDescr());
evenMax.setText((int) (curr.forecastTemp.maxEvening - 273.15) + "°C");
evenHumid.setText("%" + (int) curr.weather.currentCondition.getEvenHumidity());

Picasso.with(context).load("http://openweathermap.org/img/w/"
+ curr.weather.currentCondition.getMornIcon() + ".png")
.into(mornIcon);
Picasso.with(context).load("http://openweathermap.org/img/w/"
+ curr.weather.currentCondition.getAftIcon() + ".png")
.into(aftIcon);
Picasso.with(context).load("http://openweathermap.org/img/w/"
+ curr.weather.currentCondition.getEvenIcon() + ".png")
.into(evenIcon);
return convertView;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
DayForecast curr = dataHeader.get(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.weather_header, null);
}

TextView date = (TextView) convertView.findViewById(R.id.date);
TextView day = (TextView) convertView.findViewById(R.id.day);
TextView temp = (TextView) convertView.findViewById(R.id.temp);
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);


date.setText(curr.getStringDate());
day.setText(curr.getStringDay());
day.setTypeface(Typeface.DEFAULT_BOLD);
temp.setText((int) (curr.forecastTemp.maxTemp - 273.15) + "°C/" + (int) (curr.forecastTemp.minTemp - 273.15) + "°C");

Picasso.with(context).load("http://openweathermap.org/img/w/"
+ curr.weather.currentCondition.getAftIcon() + ".png")
.into(icon);


return convertView;
}


@Override
public int getGroupCount() {
return dataHeader.size();
}
@Override
public int getChildrenCount(int i) {
return weatherContent.get(dataHeader.get(i)).size();
}
@Override
public Object getGroup(int i) {
return dataHeader.get(i);
}
@Override
public Object getChild(int i, int i1) {
return weatherContent.get(dataHeader.get(i)).get(i1); // i = Group Item , i1 = ChildItem
}

@Override
public long getGroupId(int i) {
return i;
}
@Override
public long getChildId(int i, int i1) {
return i1;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return true;
}

}
Loading