Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.reube.droby.Database.Clothes;
import com.example.reube.droby.Database.DatabaseHandler;
import com.example.reube.droby.Database.Tag;
import com.example.reube.droby.Fragments.ClothesFragment;
import com.example.reube.droby.R;
import com.pchmn.materialchips.ChipView;
import com.pchmn.materialchips.ChipsInput;
import com.pchmn.materialchips.model.Chip;
import com.pchmn.materialchips.model.ChipInterface;
Expand Down Expand Up @@ -79,6 +81,7 @@ public void onTextChanged(CharSequence text) {
imageView.setImageBitmap(convertToBitmap(item.get(0).getImage()));
textView.setText(item.get(0).getDescription());
allTags = item.get(0).getTags();

if (allTags.size()>0){
for (int i=0;i<allTags.size();i++){
tagNoEditLayout.addChip(allTags.get(i).getName(),null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.example.reube.droby.Database.Clothes;
import com.example.reube.droby.Database.DatabaseHandler;
import com.example.reube.droby.Database.Tag;
import com.example.reube.droby.Database.User;
import com.example.reube.droby.Fragments.ClothesFragment;
import com.example.reube.droby.Fragments.MeFragment;
Expand Down Expand Up @@ -242,6 +243,19 @@ protected ArrayList<String> checkIfClothesNeedEditing(User user){
if (TextUtils.isEmpty(clothes.get(i).getDescription())){
clothes_ids.add(Integer.toString(clothes.get(i).getId()));
}
// <-- use this part on first run to set all the tags and then remove after
ArrayList<String> tags = db.getClothesTags(clothes.get(i));
ArrayList<Tag> addTag = new ArrayList<>();
for(int j =0;j<tags.size();j++){
Tag tag = new Tag();
tag.setClothes_id(clothes.get(i).getId());
tag.setName(tags.get(j));
tag.setUser_id(user.getId());
addTag.add(tag);
}
clothes.get(i).setTags(addTag);
db.updateClothes(clothes.get(i));
// until here --> //
}
return clothes_ids;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private class SyncDatabase extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
db = new DatabaseHandler(getApplicationContext());
//db.syncClothes();
db.syncClothesTags();
db.close();
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ public void setSelected(boolean selected) {
private boolean selected;
private int foregroundColour;
private boolean checkboxClickable;
private ArrayList<String> cTags;

public ArrayList<String> getCTags() {
return cTags;
}


public void setCTags(ArrayList<String> clothesTags) {
this.cTags = clothesTags;
}

@Override
public int describeContents() {
Expand Down
125 changes: 125 additions & 0 deletions app/src/main/java/com/example/reube/droby/Database/ClothesTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.example.reube.droby.Database;

import java.util.ArrayList;

/**
* Created by reube on 27/7/2017.
*/

public class ClothesTags {
private int clothes_id;
private String colour,fit,cut,weather,specific_cut,prints,embellishments,material,formality,colour_scheme,style;

public ArrayList<String> getTags(){
ArrayList<String> tags = new ArrayList<>();
tags.add(colour);
tags.add(fit);
tags.add(cut);
tags.add(weather);
tags.add(specific_cut);
tags.add(prints);
tags.add(embellishments);
tags.add(material);
tags.add(formality);
tags.add(colour_scheme);
tags.add(style);

return tags;
}

public int getClothes_id() {
return clothes_id;
}

public void setClothes_id(int clothes_id) {
this.clothes_id = clothes_id;
}

public String getColour() {
return colour;
}

public void setColour(String colour) {
this.colour = colour;
}

public String getFit() {
return fit;
}

public void setFit(String fit) {
this.fit = fit;
}

public String getCut() {
return cut;
}

public void setCut(String cut) {
this.cut = cut;
}

public String getWeather() {
return weather;
}

public void setWeather(String weather) {
this.weather = weather;
}

public String getSpecific_cut() {
return specific_cut;
}

public void setSpecific_cut(String specific_cut) {
this.specific_cut = specific_cut;
}

public String getPrints() {
return prints;
}

public void setPrints(String prints) {
this.prints = prints;
}

public String getEmbellishments() {
return embellishments;
}

public void setEmbellishments(String embellishments) {
this.embellishments = embellishments;
}

public String getMaterial() {
return material;
}

public void setMaterial(String material) {
this.material = material;
}

public String getFormality() {
return formality;
}

public void setFormality(String formality) {
this.formality = formality;
}

public String getColour_scheme() {
return colour_scheme;
}

public void setColour_scheme(String colour_scheme) {
this.colour_scheme = colour_scheme;
}

public String getStyle() {
return style;
}

public void setStyle(String style) {
this.style = style;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 6;
private MobileServiceSyncTable<Clothes> clothesMobileServiceSyncTable;
private static final int DATABASE_VERSION = 7;
// Database Name
private static final String DATABASE_NAME = "droby_database";

Expand All @@ -49,7 +48,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
private static final String TABLE_OUTFIT ="outfit";
private static final String TABLE_TAG ="tag";
private static final String TABLE_FREQUENCY = "frequency";

private static final String TABLE_CLOTHESTAGS = "clothestags";
//Common Column names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
Expand Down Expand Up @@ -84,6 +83,18 @@ public class DatabaseHandler extends SQLiteOpenHelper {
// Frequency Table Column names
private static final String KEY_DATE_WORN = "date_worn";

//ClothesTags Table Column names
private static final String KEY_COLOUR = "colour";
private static final String KEY_FIT = "fit";
private static final String KEY_CUT = "cut";
private static final String KEY_WEATHER = "weather";
private static final String KEY_SPECIFIC_CUT = "specific_cut";
private static final String KEY_PRINTS = "prints";
private static final String KEY_EMBELLISHMENTS = "embellishments";
private static final String KEY_MATERIAL = "material";
private static final String KEY_FORMALITY = "formality";
private static final String KEY_COLOUR_SCHEME = "colour_scheme";
private static final String KEY_STYLE = "style";

public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand All @@ -97,12 +108,14 @@ public void onCreate(SQLiteDatabase db) {
String CREATE_OUTFIT_TABLE = "CREATE TABLE " + TABLE_OUTFIT + "("+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+ KEY_OUTFIT_ID + " INTEGER, " + KEY_USER_ID + " INTEGER, "+ KEY_CLOTHES_ID + " INTEGER, "+ KEY_CATEGORY_ID + " TEXT, "+ KEY_NAME+" TEXT, " + KEY_IS_DELETED + " BOOLEAN " + ")";
String CREATE_TAG_TABLE = "CREATE TABLE " + TABLE_TAG + "("+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT,"+ KEY_USER_ID + " INTEGER," + KEY_CLOTHES_ID + " INTEGER," + KEY_IS_DELETED + " TEXT "+ ")";
String CREATE_FREQUENCY_TABLE = "CREATE TABLE " + TABLE_FREQUENCY + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_CLOTHES_ID + " INTEGER,"+ KEY_DATE_WORN + " DATETIME "+ ")";
String CREATE_CLOTHES_TAGS_TABLE = "CREATE TABLE " + TABLE_CLOTHESTAGS + "(" + KEY_CLOTHES_ID + " INTEGER PRIMARY KEY," + KEY_COLOUR + " TEXT," + KEY_FIT + " TEXT," +KEY_CUT + " TEXT," +KEY_WEATHER + " TEXT," +KEY_SPECIFIC_CUT + " TEXT," +KEY_PRINTS + " TEXT," +KEY_EMBELLISHMENTS + " TEXT," +KEY_MATERIAL + " TEXT," +KEY_FORMALITY + " TEXT," +KEY_COLOUR_SCHEME + " TEXT," +KEY_STYLE + " TEXT)";

db.execSQL(CREATE_USER_TABLE);
db.execSQL(CREATE_CLOTHES_TABLE);
db.execSQL(CREATE_OUTFIT_TABLE);
db.execSQL(CREATE_TAG_TABLE);
db.execSQL(CREATE_FREQUENCY_TABLE);
db.execSQL(CREATE_CLOTHES_TAGS_TABLE);
}

// Upgrading database
Expand All @@ -114,6 +127,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_OUTFIT);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_TAG);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FREQUENCY);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CLOTHESTAGS);
// Create tables again
onCreate(db);
}
Expand Down Expand Up @@ -346,6 +360,7 @@ public ArrayList<Clothes> getAllClothes(User user, ArrayList<String> clothes_ids
clothes.setCreated_date(new Date(c.getLong(c.getColumnIndex(KEY_CREATED_DATE))*1000));
clothes.setLocation(c.getInt(c.getColumnIndex(KEY_LOCATION)));
clothes.setTags(this.getTags(clothes));
clothes.setCTags(this.getClothesTags(clothes));

// Adding clothes to list
clothesList.add(clothes);
Expand Down Expand Up @@ -379,6 +394,7 @@ public ArrayList<Clothes> getAllClothes(User user, String category_id) {
clothes.setCreated_date(new Date(c.getLong(c.getColumnIndex(KEY_CREATED_DATE))*1000));
clothes.setLocation(c.getInt(c.getColumnIndex(KEY_LOCATION)));
clothes.setTags(this.getTags(clothes));
clothes.setCTags(this.getClothesTags(clothes));

// Adding clothes to list
clothesList.add(clothes);
Expand Down Expand Up @@ -412,6 +428,7 @@ public ArrayList<Clothes> getAllClothes(User user) {
clothes.setCreated_date(new Date(c.getLong(c.getColumnIndex(KEY_CREATED_DATE))*1000));
clothes.setLocation(c.getInt(c.getColumnIndex(KEY_LOCATION)));
clothes.setTags(this.getTags(clothes));
clothes.setCTags(this.getClothesTags(clothes));
// Adding clothes to list
clothesList.add(clothes);
} while (c.moveToNext());
Expand Down Expand Up @@ -497,6 +514,36 @@ public void insertDateWorn(Date date,Clothes clothes){

//Tag stuff
// NOTE: DO NOT USE THIS METHOD AS ITS MEANT TO BE USED IN GETCLOTHES
public ArrayList<String> getClothesTags(Clothes clothes){
ArrayList<String> tags = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_CLOTHESTAGS + " WHERE "+ KEY_CLOTHES_ID + " = '"+ clothes.getId()+"'";

SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()){
do{
ClothesTags ct = new ClothesTags();
ct.setClothes_id(clothes.getId());
ct.setColour(c.getString(c.getColumnIndex(KEY_COLOUR)));
ct.setFit(c.getString(c.getColumnIndex(KEY_FIT)));
ct.setCut(c.getString(c.getColumnIndex(KEY_CUT)));
ct.setWeather(c.getString(c.getColumnIndex(KEY_WEATHER)));
ct.setSpecific_cut(c.getString(c.getColumnIndex(KEY_SPECIFIC_CUT)));
ct.setPrints(c.getString(c.getColumnIndex(KEY_PRINTS)));
ct.setEmbellishments(c.getString(c.getColumnIndex(KEY_EMBELLISHMENTS)));
ct.setMaterial(c.getString(c.getColumnIndex(KEY_MATERIAL)));
ct.setFormality(c.getString(c.getColumnIndex(KEY_FORMALITY)));
ct.setColour_scheme(c.getString(c.getColumnIndex(KEY_COLOUR_SCHEME)));
ct.setStyle(c.getString(c.getColumnIndex(KEY_STYLE)));

tags.addAll(ct.getTags());
} while (c.moveToNext());
}
c.close();
db.close();
return tags;
}
// NOTE: DO NOT USE THIS METHOD AS ITS MEANT TO BE USED IN GETCLOTHES
public ArrayList<Tag> getTags(Clothes clothes){
ArrayList<Tag> tags = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_TAG + " WHERE "+ KEY_CLOTHES_ID + " = '"+ clothes.getId()+"'";// AND "+KEY_IS_DELETED+ " = '"+false+"'";
Expand Down Expand Up @@ -781,7 +828,7 @@ public void syncOutfit(){
outfit.setCategory_id(o.getString(KEY_CATEGORY_ID));
outfit.setDeleted(o.getBoolean(KEY_IS_DELETED));

String query = "INSERT OR REPLACE INTO "+ TABLE_OUTFIT + " (" + KEY_ID + ","+KEY_USER_ID+ "," + KEY_NAME + "," + KEY_OUTFIT_ID+ ","+ KEY_CLOTHES_ID +","+ KEY_CATEGORY_ID +", " + KEY_IS_DELETED+") VALUES ("+outfit.getId()+ ","+outfit.getUser_id()+ ","+outfit.getName()+ ","+outfit.getOutfit_id()+ ","+outfit.getClothes_id()+"," + outfit.getCategory_id()+"," + outfit.isDeleted()+ ")";
String query = "INSERT OR REPLACE INTO "+ TABLE_OUTFIT + " (" + KEY_ID + ","+KEY_USER_ID+ "," + KEY_NAME + "," + KEY_OUTFIT_ID+ ","+ KEY_CLOTHES_ID +","+ KEY_CATEGORY_ID +", " + KEY_IS_DELETED+") VALUES ('"+outfit.getId()+ "','"+outfit.getUser_id()+ "','"+outfit.getName()+ "','"+outfit.getOutfit_id()+ "','"+outfit.getClothes_id()+"','" + outfit.getCategory_id()+"','" + outfit.isDeleted()+ "')";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
cursor.close();
Expand Down Expand Up @@ -880,4 +927,40 @@ public ArrayList<byte[]> syncTest(){
} return pics;
}

//Sync clothesTags
public void syncClothesTags(){
String statement = "Select * from clothestags";
String result = DatabaseUtilities.getResult(statement);
if (result!=null) {
try {
JSONArray tags = new JSONArray(result);
for (int i = 0; i < tags.length(); i++) {
JSONObject o = tags.getJSONObject(i);

ContentValues values = new ContentValues();
values.put(KEY_CLOTHES_ID,o.getInt(KEY_CLOTHES_ID));
values.put(KEY_COLOUR,o.getString(KEY_COLOUR));
values.put(KEY_FIT,o.getString(KEY_FIT));
values.put(KEY_CUT,o.getString(KEY_CUT));
values.put(KEY_WEATHER,o.getString(KEY_WEATHER));
values.put(KEY_SPECIFIC_CUT,o.getString(KEY_SPECIFIC_CUT));
values.put(KEY_PRINTS,o.getString(KEY_PRINTS));
values.put(KEY_EMBELLISHMENTS,o.getString(KEY_EMBELLISHMENTS));
values.put(KEY_MATERIAL,o.getString(KEY_MATERIAL));
values.put(KEY_FORMALITY,o.getString(KEY_FORMALITY));
values.put(KEY_COLOUR_SCHEME,o.getString(KEY_COLOUR_SCHEME));
values.put(KEY_STYLE,o.getString(KEY_STYLE));

SQLiteDatabase db = this.getWritableDatabase();
// updating row
db.replace(TABLE_CLOTHESTAGS, null,values);
db.close();
}
} catch (JSONException e){
Log.e(TAG, "Json parsing error: " + e.getMessage());

}
}
}

}
Binary file modified app/src/main/res/drawable/icon.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_clothes_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
app:chip_hasAvatarIcon="false"
app:chip_labelColor="@color/white"
app:chip_deletable="false"
app:maxRows="3"
app:hint="Enter a tag"

app:showChipDetailed="false" />
Expand All @@ -79,6 +80,7 @@
app:chip_hasAvatarIcon="false"
app:chip_labelColor="@color/white"
app:chip_deletable="true"
app:maxRows="3"
app:hint="Enter a tag"
app:showChipDetailed="false" />

Expand Down