-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHome.cs
144 lines (131 loc) · 4.82 KB
/
Home.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
namespace Instagram
{
public partial class Home : Form
{
bool lightModeOn = false;
DBHandlingUtilities dbHandler;
UIUtilities UI;
List<string[]> usersList;
string ImageNewName = "";
int listViewItemsCount = 0;
ImageList listViewImageList = new ImageList();
Post[] postList;
string userName = "", userID = "";
Main main;
public Home(Main main)
{
InitializeComponent();
this.main = main;
this.lightModeOn = main.lightModeOn;
this.userID = main.userID;
this.userName = main.userName;
dbHandler = new DBHandlingUtilities();
UI = new UIUtilities(this, lightModeOn);
Configure_Theme();
Import_All_Following();
}
private void Configure_Theme()
{
Color backColor, foreColor;
if (lightModeOn)
{
backColor = Color.FromArgb(255, 255, 255);
foreColor = Color.FromArgb(209, 209, 209);
}
else
{
backColor = Color.FromArgb(43, 43, 43);
foreColor = Color.FromArgb(31, 31, 31);
}
this.BackColor = foreColor;
storyListView.BackColor = backColor;
feedPanel.BackColor = foreColor;
}
private void Import_All_Following()
{
usersList = dbHandler.Import_Data_Using_SQL(userID, userName, "FollowingTable");
dbHandler.Truncate_Temporary_Post_Table();
Generate_Posts_And_Stories(usersList);
postList = dbHandler.Generate_Posts(userID, userName, lightModeOn, main);
Display_Posts();
}
private void Display_Posts()
{
feedPanel.AutoScroll = true;
for(int i=0; i< postList.Length;i++)
{
postList[i].TopLevel = false;
feedPanel.Controls.Add(postList[i]);
postList[i].Show();
}
}
private void Add_All_Stories(string userID, string userName)
{
dbHandler.Create_Valid_Story_View(userID, userName);
if (dbHandler.Check_If_Story_Exists(userID, userName))
{
try
{
listViewImageList.Images.Add(dbHandler.Retrieve_Profile_Picture_Using_SQL(Int32.Parse(userID)));
storyListView.Items.Add(new ListViewItem
{
ImageIndex = listViewItemsCount,
Text = userName,
Tag = userName + '_' + userID
}); ; ; ; ; ; ;
listViewItemsCount++;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
private void Add_All_Post(string userID, string userName)
{
dbHandler.Create_View_For_Following_Posts(userID,userName);
}
public void Generate_Posts_And_Stories(List<string[]> usersList)
{
listViewImageList.ImageSize = new Size(50, 50);
for (int i = 0; i < usersList.Count; i++)
{
Add_All_Stories(usersList[i][1], usersList[i][2]);
Add_All_Post(usersList[i][1], usersList[i][2]);
}
storyListView.LargeImageList = listViewImageList;
}
private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
if (e.Label == null)
return;
ImageNewName = Convert.ToString(e.Label);
ListViewItem item1 = storyListView.SelectedItems[0];
FileInfo fileInfo = new FileInfo(item1.Tag.ToString());
fileInfo.MoveTo(fileInfo.Directory.FullName + "\\" + ImageNewName + fileInfo.Extension);
storyListView.Items[listViewItemsCount].Text = ImageNewName;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (storyListView.SelectedIndices.Count <= 0)
{
Console.WriteLine(storyListView.SelectedItems.Count);
return;
}
if (storyListView.SelectedIndices[0] >= 0)
{
var item = storyListView.SelectedItems[0];
Image img = listViewImageList.Images[item.ImageIndex];
this.Hide();
Story story = new Story(storyListView.SelectedItems[0].Tag.ToString(), img, main){ TopLevel = false, TopMost = true };;
main.formVirtualizer.Controls.Add(story);
story.Show();
}
}
}
}